WL-1518 | Get decline notification context from enterprise.

This commit is contained in:
Hasnain
2018-03-28 18:07:47 +05:00
parent e0d20be11d
commit 3fca1af171
3 changed files with 69 additions and 18 deletions

View File

@@ -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',

View File

@@ -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:

View File

@@ -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