From e942f12adc7d396ab210443ab3e710f53d7caf57 Mon Sep 17 00:00:00 2001 From: Shimul Chowdhury Date: Fri, 5 Feb 2021 22:43:24 +0600 Subject: [PATCH] Add missing context platform_name and contact_mailing_address. And pass site configuration to email context. --- cms/envs/common.py | 3 +++ common/djangoapps/student/email_helpers.py | 5 +++++ lms/djangoapps/instructor/enrollment.py | 10 ++++++++++ .../djangoapps/ace_common/template_context.py | 6 ++++++ .../schedules/tests/test_resolvers.py | 2 ++ .../djangoapps/site_configuration/helpers.py | 19 +++++++++++++++++++ .../site_configuration/tests/test_helpers.py | 14 ++++++++++++++ 7 files changed, 59 insertions(+) diff --git a/cms/envs/common.py b/cms/envs/common.py index 44d00a248a..f9cce8a341 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -157,6 +157,9 @@ BLOCK_STRUCTURES_SETTINGS = dict( ############################ FEATURE CONFIGURATION ############################# PLATFORM_NAME = _('Your Platform Name Here') + +CONTACT_MAILING_ADDRESS = _('Your Contact Mailing Address Here') + PLATFORM_DESCRIPTION = _('Your Platform Description Here') PLATFORM_FACEBOOK_ACCOUNT = "http://www.facebook.com/YourPlatformFacebookAccount" diff --git a/common/djangoapps/student/email_helpers.py b/common/djangoapps/student/email_helpers.py index cd7ccfe5fa..3da7eae56c 100644 --- a/common/djangoapps/student/email_helpers.py +++ b/common/djangoapps/student/email_helpers.py @@ -28,10 +28,15 @@ def generate_activation_email_context(user, registration): 'key': registration.activation_key, 'lms_url': configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL), 'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), + 'contact_mailing_address': configuration_helpers.get_value( + 'contact_mailing_address', + settings.CONTACT_MAILING_ADDRESS + ), 'support_url': configuration_helpers.get_value( 'ACTIVATION_EMAIL_SUPPORT_LINK', settings.ACTIVATION_EMAIL_SUPPORT_LINK ) or settings.SUPPORT_SITE_LINK, 'support_email': configuration_helpers.get_value('CONTACT_EMAIL', settings.CONTACT_EMAIL), + 'site_configuration_values': configuration_helpers.get_current_site_configuration_values(), }) return context diff --git a/lms/djangoapps/instructor/enrollment.py b/lms/djangoapps/instructor/enrollment.py index 491571bf1d..f657be7f4e 100644 --- a/lms/djangoapps/instructor/enrollment.py +++ b/lms/djangoapps/instructor/enrollment.py @@ -427,6 +427,13 @@ def get_email_params(course, auto_enroll, secure=True, course_key=None, display_ is_shib_course = uses_shib(course) + # Collect mailing address and platform name to pass as context + contact_mailing_address = configuration_helpers.get_value( + 'contact_mailing_address', + settings.CONTACT_MAILING_ADDRESS + ) + platform_name = configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME) + # Composition of email email_params = { 'site_name': stripped_site_name, @@ -437,6 +444,9 @@ def get_email_params(course, auto_enroll, secure=True, course_key=None, display_ 'course_url': course_url, 'course_about_url': course_about_url, 'is_shib_course': is_shib_course, + 'contact_mailing_address': contact_mailing_address, + 'platform_name': platform_name, + 'site_configuration_values': configuration_helpers.get_current_site_configuration_values(), } return email_params diff --git a/openedx/core/djangoapps/ace_common/template_context.py b/openedx/core/djangoapps/ace_common/template_context.py index 303bfcc204..0589a29fc4 100644 --- a/openedx/core/djangoapps/ace_common/template_context.py +++ b/openedx/core/djangoapps/ace_common/template_context.py @@ -21,6 +21,11 @@ def get_base_template_context(site): except NoReverseMatch: dashboard_url = reverse('home') + if hasattr(site, 'configuration'): + site_configuration_values = site.configuration.site_values + else: + site_configuration_values = {} + return { # Platform information 'homepage_url': marketing_link('ROOT'), @@ -38,4 +43,5 @@ def get_base_template_context(site): 'social_media_urls': get_config_value_from_site_or_settings('SOCIAL_MEDIA_FOOTER_URLS', site=site), 'mobile_store_urls': get_config_value_from_site_or_settings('MOBILE_STORE_URLS', site=site), 'logo_url': get_logo_url_for_email(), + 'site_configuration_values': site_configuration_values, } diff --git a/openedx/core/djangoapps/schedules/tests/test_resolvers.py b/openedx/core/djangoapps/schedules/tests/test_resolvers.py index 71bd0fc10e..957f779369 100644 --- a/openedx/core/djangoapps/schedules/tests/test_resolvers.py +++ b/openedx/core/djangoapps/schedules/tests/test_resolvers.py @@ -175,6 +175,7 @@ class TestCourseUpdateResolver(SchedulesResolverTestMixin, ModuleStoreTestCase): 'logo_url': 'https://www.logo.png', 'platform_name': '\xe9dX', 'show_upsell': False, + 'site_configuration_values': {}, 'social_media_urls': {}, 'template_revision': 'release', 'unsubscribe_url': None, @@ -263,6 +264,7 @@ class TestCourseNextSectionUpdateResolver(SchedulesResolverTestMixin, ModuleStor 'logo_url': 'https://www.logo.png', 'platform_name': '\xe9dX', 'show_upsell': False, + 'site_configuration_values': {}, 'social_media_urls': {}, 'template_revision': 'release', 'unsubscribe_url': None, diff --git a/openedx/core/djangoapps/site_configuration/helpers.py b/openedx/core/djangoapps/site_configuration/helpers.py index a910c4fb71..dd99297cf9 100644 --- a/openedx/core/djangoapps/site_configuration/helpers.py +++ b/openedx/core/djangoapps/site_configuration/helpers.py @@ -29,6 +29,25 @@ def get_current_site_configuration(): return None +def get_current_site_configuration_values(default=None): + """ + Returns `SiteConfiguration.site_values` for current site. + Args: + default (dict): default value (`{}` if not specified) to return if site configuration is not available. + Returns: + (dict) Site Configuration value for the current site or default + """ + if default is None: + default = {} + + site_configuration = get_current_site_configuration() + + if site_configuration: + return site_configuration.site_values + else: + return default + + def is_site_configuration_enabled(): """ Returns True is there is SiteConfiguration instance associated with the current site and it is enabled, otherwise diff --git a/openedx/core/djangoapps/site_configuration/tests/test_helpers.py b/openedx/core/djangoapps/site_configuration/tests/test_helpers.py index dd02bce950..7b71d2f7f3 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_helpers.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_helpers.py @@ -169,3 +169,17 @@ class TestHelpers(TestCase): list(configuration_helpers.get_current_site_orgs()), test_orgs ) + + def test_get_current_site_configuration_values(self): + """ + Test get_current_site_configuration_values helper function + """ + site_values = configuration_helpers.get_current_site_configuration_values() + self.assertTrue(isinstance(site_values, dict)) + + # without any site configuration it should return empty dict + self.assertEqual(site_values, {}) + + with with_site_configuration_context(configuration=test_config): + site_values = configuration_helpers.get_current_site_configuration_values() + self.assertEqual(site_values, test_config)