diff --git a/openedx/features/enterprise_support/api.py b/openedx/features/enterprise_support/api.py index b5ab3d5da66255e11956a585c933d04b99ea0640..afa044adaf07881a3766387c1ed4cfb67be47e73 100644 --- a/openedx/features/enterprise_support/api.py +++ b/openedx/features/enterprise_support/api.py @@ -22,8 +22,8 @@ from third_party_auth.pipeline import get as get_partial_pipeline from third_party_auth.provider import Registry try: - from consent.models import DataSharingConsent from enterprise.models import EnterpriseCustomer, EnterpriseCustomerUser + from consent.models import DataSharingConsent, DataSharingConsentTextOverrides except ImportError: pass @@ -525,6 +525,25 @@ def get_enterprise_customer_for_learner(site, user): return {} +def get_consent_notification_data(enterprise_customer): + """ + Returns the consent notification data from DataSharingConsentPage modal + """ + title_template = None + message_template = None + try: + consent_page = DataSharingConsentTextOverrides.objects.get(enterprise_customer_id=enterprise_customer['uuid']) + title_template = consent_page.declined_notification_title + message_template = consent_page.declined_notification_message + except DataSharingConsentTextOverrides.DoesNotExist: + LOGGER.info( + "DataSharingConsentPage object doesn't exit for {enterprise_customer_name}".format( + enterprise_customer_name=enterprise_customer['name'] + ) + ) + return title_template, message_template + + def get_dashboard_consent_notification(request, user, course_enrollments): """ If relevant to the request at hand, create a banner on the dashboard indicating consent failed. @@ -564,19 +583,23 @@ def get_dashboard_consent_notification(request, user, course_enrollments): if consent_needed and enrollment: - message_template = _( - 'If you have concerns about sharing your data, please contact your administrator ' - 'at {enterprise_customer_name}.' - ) + title_template, message_template = get_consent_notification_data(enterprise_customer) + if not title_template: + title_template = _( + 'Enrollment in {course_title} was not complete.' + ) + if not message_template: + message_template = _( + 'If you have concerns about sharing your data, please contact your administrator ' + 'at {enterprise_customer_name}.' + ) + title = title_template.format( + course_title=enrollment.course_overview.display_name, + ) message = message_template.format( enterprise_customer_name=enterprise_customer['name'], ) - title = _( - 'Enrollment in {course_name} was not complete.' - ).format( - course_name=enrollment.course_overview.display_name, - ) return render_to_string( 'enterprise_support/enterprise_consent_declined_notification.html', diff --git a/openedx/features/enterprise_support/tests/test_api.py b/openedx/features/enterprise_support/tests/test_api.py index 5481c1bb406477c4c7e50f0311b6a47c1ee20239..554f35eb6159c1edefdaad599812b7bb6d3aea63 100644 --- a/openedx/features/enterprise_support/tests/test_api.py +++ b/openedx/features/enterprise_support/tests/test_api.py @@ -401,11 +401,11 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase): self.assertEqual(actual_url, expected_url) @ddt.data( - (False, {'real': 'enterprise', 'uuid': ''}, 'course', [], []), - (True, {}, 'course', [], []), - (True, {'real': 'enterprise'}, None, [], []), - (True, {'name': 'GriffCo', 'uuid': ''}, 'real-course', [], []), - (True, {'name': 'GriffCo', 'uuid': ''}, 'real-course', [MockEnrollment(course_id='other-id')], []), + (False, {'real': 'enterprise', 'uuid': ''}, 'course', [], [], "", ""), + (True, {}, 'course', [], [], "", ""), + (True, {'real': 'enterprise'}, None, [], [], "", ""), + (True, {'name': 'GriffCo', 'uuid': ''}, 'real-course', [], [], "", ""), + (True, {'name': 'GriffCo', 'uuid': ''}, 'real-course', [MockEnrollment(course_id='other-id')], [], "", ""), ( True, {'name': 'GriffCo', 'uuid': 'real-uuid'}, @@ -421,13 +421,34 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase): [ 'If you have concerns about sharing your data, please contact your administrator at GriffCo.', 'Enrollment in My Cool Course was not complete.' - ] + ], + "", "" + ), + ( + True, + {'name': 'GriffCo', 'uuid': 'real-uuid'}, + 'real-course', + [ + MockEnrollment( + course_id='real-course', + course_overview=mock.MagicMock( + display_name='My Cool Course' + ) + ) + ], + [ + 'If you have concerns about sharing your data, please contact your administrator at GriffCo.', + 'Enrollment in My Cool Course was not complete.' + ], + "Title from DataSharingConsentTextOverrides model in consent app", + "Message from DataSharingConsentTextOverrides model in consent app" ), ) @ddt.unpack @mock.patch('openedx.features.enterprise_support.api.ConsentApiClient') @mock.patch('openedx.features.enterprise_support.api.enterprise_customer_for_request') + @mock.patch('openedx.features.enterprise_support.api.get_consent_notification_data') def test_get_dashboard_consent_notification( self, consent_return_value, @@ -435,12 +456,16 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase): course_id, enrollments, expected_substrings, + notification_title, + notification_message, + consent_notification_data, ec_for_request, consent_client_class ): request = mock.MagicMock( GET={'consent_failed': course_id} ) + consent_notification_data.return_value = notification_title, notification_message consent_client = consent_client_class.return_value consent_client.consent_required.return_value = consent_return_value @@ -452,7 +477,10 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase): request, user, enrollments, ) - if expected_substrings: + if notification_message and notification_title: + self.assertIn(notification_title, notification_string) + self.assertIn(notification_message, notification_string) + elif expected_substrings: for substr in expected_substrings: self.assertIn(substr, notification_string) else: diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index b2439bea0eecbd42ec2285bd58dd665e6c25870e..e3b2c0ec71351ab13b400447121ae32039154138 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -126,7 +126,7 @@ edx-django-oauth2-provider==1.2.5 edx-django-release-util==0.3.1 edx-django-sites-extensions==2.3.1 edx-drf-extensions==1.2.5 -edx-enterprise==0.67.4 +edx-enterprise==0.67.5 edx-i18n-tools==0.4.4 edx-milestones==0.1.13 edx-oauth2-provider==1.2.2