Update mocks/docs/code to reflect Enterprise API updates.

This commit is contained in:
Uman Shahzad
2017-10-01 04:35:50 +05:00
parent db6570b754
commit 2601b26af6
4 changed files with 72 additions and 48 deletions

View File

@@ -212,7 +212,7 @@ class EnterpriseApiClient(object):
},
"data_sharing_consent_records": [
{
"username": "myself",
"username": "staff",
"enterprise_customer_uuid": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"exists": true,
"course_id": "course-v1:edX DemoX Demo_Course",
@@ -324,18 +324,15 @@ def enterprise_enabled():
return 'enterprise' in settings.INSTALLED_APPS and getattr(settings, 'ENABLE_ENTERPRISE_INTEGRATION', True)
def enterprise_customer_for_request(request):
def enterprise_customer_uuid_for_request(request):
"""
Check all the context clues of the request to determine if
the request being made is tied to a particular EnterpriseCustomer.
Check all the context clues of the request to gather a particular EnterpriseCustomer's UUID.
"""
if not enterprise_enabled():
return None
enterprise_customer = None
enterprise_customer_uuid = None
sso_provider_id = request.GET.get('tpa_hint')
running_pipeline = get_partial_pipeline(request)
if running_pipeline:
# Determine if the user is in the middle of a third-party auth pipeline,
@@ -354,9 +351,7 @@ def enterprise_customer_for_request(request):
enterprise_customer_identity_provider__provider_id=sso_provider_id
).uuid
except EnterpriseCustomer.DoesNotExist:
# If there is not an EnterpriseCustomer linked to this SSO provider, set
# the UUID variable to be null.
enterprise_customer_uuid = None
pass
else:
# Check if we got an Enterprise UUID passed directly as either a query
# parameter, or as a value in the Enterprise cookie.
@@ -371,6 +366,16 @@ def enterprise_customer_for_request(request):
if learner_data:
enterprise_customer_uuid = learner_data[0]['enterprise_customer']['uuid']
return enterprise_customer_uuid
def enterprise_customer_for_request(request):
"""
Check all the context clues of the request to determine if
the request being made is tied to a particular EnterpriseCustomer.
"""
enterprise_customer = None
enterprise_customer_uuid = enterprise_customer_uuid_for_request(request)
if enterprise_customer_uuid:
# If we were able to obtain an EnterpriseCustomer UUID, go ahead
# and use it to attempt to retrieve EnterpriseCustomer details
@@ -437,8 +442,7 @@ def get_enterprise_consent_url(request, course_id, user=None, return_to=None, en
if not enterprise_enabled():
return ''
if user is None:
user = request.user
user = user or request.user
if not consent_needed_for_course(request, user, course_id, enrollment_exists=enrollment_exists):
return None
@@ -449,6 +453,7 @@ def get_enterprise_consent_url(request, course_id, user=None, return_to=None, en
return_path = reverse(return_to, args=(course_id,))
url_params = {
'enterprise_customer_uuid': enterprise_customer_uuid_for_request(request),
'course_id': course_id,
'next': request.build_absolute_uri(return_path),
'failure_url': request.build_absolute_uri(