From bd693f025d60042e50cc0296f459fca71d40281d Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 15 Oct 2020 12:27:11 +0200 Subject: [PATCH 1/2] Add our `readthedocs_processor` data to our notifications This fixes an issue where we were sending emails with `Contact us at {{ SUPPORT_EMAIL }}` but the support email variable was not set and the result was an empty email. Using our own `readthedocs_processor` here we are passing all the same variables to the notification that to all the Django templates, avoiding this kind of confusions. --- readthedocs/notifications/notification.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readthedocs/notifications/notification.py b/readthedocs/notifications/notification.py index c096d591f9a..592fdf1c73a 100644 --- a/readthedocs/notifications/notification.py +++ b/readthedocs/notifications/notification.py @@ -3,6 +3,7 @@ """Support for templating of notifications.""" import logging +from readthedocs.core.context_processors import readthedocs_processor from django.conf import settings from django.db import models @@ -50,7 +51,7 @@ def get_subject(self): return template.render(context=Context(self.get_context_data())) def get_context_data(self): - return { + context = { self.context_object_name: self.object, 'request': self.request, 'production_uri': '{scheme}://{host}'.format( @@ -58,6 +59,8 @@ def get_context_data(self): host=settings.PRODUCTION_DOMAIN, ), } + context.update(readthedocs_processor(self.request)) + return context def get_template_names(self, backend_name, source_format=constants.HTML): names = [] From 656862a9152c88419ed21a847403781a005269ab Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 22 Oct 2020 11:09:36 +0200 Subject: [PATCH 2/2] Check the readthedocs_processor in the notification's context --- .../rtd_tests/tests/test_notifications.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/readthedocs/rtd_tests/tests/test_notifications.py b/readthedocs/rtd_tests/tests/test_notifications.py index afd19a00e9c..5a3d00f60ed 100644 --- a/readthedocs/rtd_tests/tests/test_notifications.py +++ b/readthedocs/rtd_tests/tests/test_notifications.py @@ -67,6 +67,18 @@ class TestNotification(Notification): 'foo': build, 'production_uri': 'https://readthedocs.org', 'request': req, + + # readthedocs_processor context + 'DASHBOARD_ANALYTICS_CODE': None, + 'DO_NOT_TRACK_ENABLED': False, + 'GLOBAL_ANALYTICS_CODE': None, + 'PRODUCTION_DOMAIN': 'readthedocs.org', + 'PUBLIC_DOMAIN': None, + 'SITE_ROOT': mock.ANY, + 'SUPPORT_EMAIL': None, + 'TEMPLATE_ROOT': mock.ANY, + 'USE_PROMOS': False, + 'USE_SUBDOMAIN': False, }, ) @@ -220,6 +232,18 @@ def test_context_data(self): 'request': None, 'production_uri': 'https://readthedocs.org', 'other': {'name': 'other name'}, + + # readthedocs_processor context + 'DASHBOARD_ANALYTICS_CODE': None, + 'DO_NOT_TRACK_ENABLED': False, + 'GLOBAL_ANALYTICS_CODE': None, + 'PRODUCTION_DOMAIN': 'readthedocs.org', + 'PUBLIC_DOMAIN': None, + 'SITE_ROOT': mock.ANY, + 'SUPPORT_EMAIL': None, + 'TEMPLATE_ROOT': mock.ANY, + 'USE_PROMOS': False, + 'USE_SUBDOMAIN': False, } self.assertEqual(self.n.get_context_data(), context)