Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 8 additions & 45 deletions openedx/features/enterprise_support/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,12 @@ def consent_required(self, enrollment_exists=False, **kwargs):
"""

# Call the endpoint with the given kwargs, and check the value that it provides.
LOGGER.info(
u"Calling enterprise consent API for user [{username}] and course [{course_id}].".format(
username=kwargs.get('username'),
course_id=kwargs.get('course_id')
)
)
response = self.consent_endpoint.get(**kwargs)

# No Enterprise record exists, but we're already enrolled in a course. So, go ahead and proceed.
if enrollment_exists and not response.get('exists', False):
LOGGER.info(
u"No enterprise record exists for user [{username}] and course [{course_id}], but the user is already "
u"enrolled, so consent is not required.".format(
username=kwargs.get('username'),
course_id=kwargs.get('course_id')
)
)

return False

LOGGER.info(
u"The response from the Enterprise API to check if consent is required for user [{username}] and course "
u"[{course_id}] is [{required}]. ".format(
username=kwargs.get('username'),
course_id=kwargs.get('course_id'),
required=response['consent_required']
)
)

# In all other cases, just trust the Consent API.
return response['consent_required']

Expand Down Expand Up @@ -576,7 +553,6 @@ def consent_needed_for_course(request, user, course_id, enrollment_exists=False)
return False

enterprise_learner_details = get_enterprise_learner_data_from_db(user)
consent_needed = False
if not enterprise_learner_details:
LOGGER.info(
u"Consent from user [{username}] is not needed for course [{course_id}]. The user is not linked to an"
Expand All @@ -588,31 +564,18 @@ def consent_needed_for_course(request, user, course_id, enrollment_exists=False)
else:
client = ConsentApiClient(user=request.user)
current_enterprise_uuid = enterprise_customer_uuid_for_request(request)
for learner in enterprise_learner_details:
if current_enterprise_uuid != learner['enterprise_customer']['uuid']:
# ignore details for enterprises other than the one the learner is currently logged in as
continue
if Site.objects.get(domain=learner['enterprise_customer']['site']['domain']) != request.site:
LOGGER.info(
u"Consent check for user [{username}] and course [{course_id}] found a site mismatch. The learner "
u"details site [{learner_site}] doesn't match the request site [{request_site}]".format(
username=user.username,
course_id=course_id,
learner_site=learner['enterprise_customer']['site']['domain'],
request_site=request.site
)
)
# ignore details for enterprises whose site doesn't match the request site
continue
if client.consent_required(
consent_needed = any(
current_enterprise_uuid == learner['enterprise_customer']['uuid']
and Site.objects.get(domain=learner['enterprise_customer']['site']['domain']) == request.site
and client.consent_required(
username=user.username,
course_id=course_id,
enterprise_customer_uuid=current_enterprise_uuid,
enrollment_exists=enrollment_exists,
):
# consent is required, no longer necessary to check other details
consent_needed = True
break
)
for learner in enterprise_learner_details
)

if consent_needed:
LOGGER.info(
u"Consent from user [{username}] is needed for course [{course_id}]. The user's current enterprise"
Expand Down