|
|
|
|
@@ -147,22 +147,25 @@ def _can_generate_allowlist_certificate(user, course_key):
|
|
|
|
|
"""
|
|
|
|
|
if not is_using_certificate_allowlist(course_key):
|
|
|
|
|
# This course run is not using the allowlist feature
|
|
|
|
|
log.info(f'{course_key} is not using the certificate allowlist. Certificate cannot be generated.')
|
|
|
|
|
log.info(f'{course_key} is not using the certificate allowlist. Allowlist certificate cannot be generated'
|
|
|
|
|
f'for {user.id}.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not auto_certificate_generation_enabled():
|
|
|
|
|
# Automatic certificate generation is globally disabled
|
|
|
|
|
log.info('Automatic certificate generation is globally disabled. Certificate cannot be generated.')
|
|
|
|
|
log.info(f'Automatic certificate generation is globally disabled. Allowlist certificate cannot be generated'
|
|
|
|
|
f'for {user.id} : {course_key}.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if CertificateInvalidation.has_certificate_invalidation(user, course_key):
|
|
|
|
|
# The invalidation list overrides the allowlist
|
|
|
|
|
log.info(f'{user.id} : {course_key} is on the certificate invalidation list. Certificate cannot be generated.')
|
|
|
|
|
log.info(f'{user.id} : {course_key} is on the certificate invalidation list. Allowlist certificate cannot be '
|
|
|
|
|
f'generated.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
enrollment_mode, __ = CourseEnrollment.enrollment_mode_for_user(user, course_key)
|
|
|
|
|
if enrollment_mode is None:
|
|
|
|
|
log.info(f'{user.id} : {course_key} does not have an enrollment. Certificate cannot be generated.')
|
|
|
|
|
log.info(f'{user.id} : {course_key} does not have an enrollment. Allowlist certificate cannot be generated.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not modes_api.is_eligible_for_certificate(enrollment_mode):
|
|
|
|
|
@@ -171,16 +174,16 @@ def _can_generate_allowlist_certificate(user, course_key):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not IDVerificationService.user_is_verified(user):
|
|
|
|
|
log.info(f'{user.id} does not have a verified id. Certificate cannot be generated.')
|
|
|
|
|
log.info(f'{user.id} does not have a verified id. Allowlist certificate cannot be generated for {course_key}.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if not _is_on_certificate_allowlist(user, course_key):
|
|
|
|
|
log.info(f'{user.id} : {course_key} is not on the certificate allowlist. Certificate cannot be generated.')
|
|
|
|
|
log.info(f'{user.id} : {course_key} is not on the certificate allowlist. Allowlist certificate cannot be '
|
|
|
|
|
f'generated.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
log.info(f'{user.id} : {course_key} is on the certificate allowlist')
|
|
|
|
|
cert = GeneratedCertificate.certificate_for_student(user, course_key)
|
|
|
|
|
return _can_generate_allowlist_certificate_for_status(cert)
|
|
|
|
|
return _can_generate_allowlist_certificate_for_status(user, course_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _can_generate_v2_certificate(user, course_key):
|
|
|
|
|
@@ -228,22 +231,22 @@ def _is_on_certificate_allowlist(user, course_key):
|
|
|
|
|
return CertificateWhitelist.objects.filter(user=user, course_id=course_key, whitelist=True).exists()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _can_generate_allowlist_certificate_for_status(cert):
|
|
|
|
|
def _can_generate_allowlist_certificate_for_status(user, course_key):
|
|
|
|
|
"""
|
|
|
|
|
Check if the user's certificate status allows certificate generation
|
|
|
|
|
Check if the user's certificate status can handle allowlist certificate generation
|
|
|
|
|
"""
|
|
|
|
|
cert = GeneratedCertificate.certificate_for_student(user, course_key)
|
|
|
|
|
if cert is None:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
if cert.status == CertificateStatuses.downloadable:
|
|
|
|
|
log.info('Certificate with status {status} already exists for {user} : {course}, and is NOT eligible for '
|
|
|
|
|
'allowlist generation. Certificate cannot be generated.'
|
|
|
|
|
.format(status=cert.status, user=cert.user.id, course=cert.course_id))
|
|
|
|
|
log.info(f'Certificate with status {cert.status} already exists for {user.id} : {course_key}, and is not '
|
|
|
|
|
f'eligible for allowlist generation. Allowlist certificate cannot be generated as it is already in a '
|
|
|
|
|
f'final state.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
log.info('Certificate with status {status} already exists for {user} : {course}, and is eligible for allowlist '
|
|
|
|
|
'generation'
|
|
|
|
|
.format(status=cert.status, user=cert.user.id, course=cert.course_id))
|
|
|
|
|
log.info(f'Certificate with status {cert.status} already exists for {user.id} : {course_key}, and is eligible for '
|
|
|
|
|
f'allowlist generation')
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|