Merge pull request #16163 from edx/bfiller/fix-dsc-banner
Display banner if user declines data sharing consent
This commit is contained in:
@@ -364,6 +364,13 @@ def enterprise_customer_for_request(request):
|
||||
settings.ENTERPRISE_CUSTOMER_COOKIE_NAME
|
||||
)
|
||||
|
||||
if not enterprise_customer_uuid and request.user.is_authenticated():
|
||||
# If there's no way to get an Enterprise UUID for the request, check to see
|
||||
# if there's already an Enterprise attached to the requesting user on the backend.
|
||||
learner_data = get_enterprise_learner_data(request.site, request.user)
|
||||
if learner_data:
|
||||
enterprise_customer_uuid = learner_data[0]['enterprise_customer']['uuid']
|
||||
|
||||
if enterprise_customer_uuid:
|
||||
# If we were able to obtain an EnterpriseCustomer UUID, go ahead
|
||||
# and use it to attempt to retrieve EnterpriseCustomer details
|
||||
|
||||
@@ -171,6 +171,7 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
|
||||
self.assertFalse(consent_needed_for_course(request, user, 'fake-course'))
|
||||
|
||||
@httpretty.activate
|
||||
@mock.patch('openedx.features.enterprise_support.api.get_enterprise_learner_data')
|
||||
@mock.patch('openedx.features.enterprise_support.api.EnterpriseCustomer')
|
||||
@mock.patch('openedx.features.enterprise_support.api.get_partial_pipeline')
|
||||
@mock.patch('openedx.features.enterprise_support.api.Registry')
|
||||
@@ -179,6 +180,7 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
|
||||
mock_registry,
|
||||
mock_partial,
|
||||
mock_enterprise_customer_model,
|
||||
mock_get_enterprise_learner_data,
|
||||
):
|
||||
def mock_get_enterprise_customer(**kwargs):
|
||||
uuid = kwargs.get('enterprise_customer_identity_provider__provider_id')
|
||||
@@ -227,6 +229,16 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
|
||||
)
|
||||
self.assertEqual(enterprise_customer, {'real': 'enterprisecustomer'})
|
||||
|
||||
# Verify that we can still get enterprise customer from enterprise
|
||||
# learner API even if we are unable to get it from preferred sources,
|
||||
# e.g. url query parameters, third-party auth pipeline, enterprise
|
||||
# cookie.
|
||||
mock_get_enterprise_learner_data.return_value = [{'enterprise_customer': {'uuid': 'real-ent-uuid'}}]
|
||||
enterprise_customer = enterprise_customer_for_request(
|
||||
mock.MagicMock(GET={}, COOKIES={}, user=self.user, site=1)
|
||||
)
|
||||
self.assertEqual(enterprise_customer, {'real': 'enterprisecustomer'})
|
||||
|
||||
def check_data_sharing_consent(self, consent_required=False, consent_url=None):
|
||||
"""
|
||||
Used to test the data_sharing_consent_required view decorator.
|
||||
|
||||
Reference in New Issue
Block a user