diff --git a/lms/djangoapps/certificates/services.py b/lms/djangoapps/certificates/services.py index ae4cd51ba33a..e2e180df80a5 100644 --- a/lms/djangoapps/certificates/services.py +++ b/lms/djangoapps/certificates/services.py @@ -8,6 +8,7 @@ from django.core.exceptions import ObjectDoesNotExist from opaque_keys.edx.keys import CourseKey +from lms.djangoapps.certificates.models import CertificateWhitelist from lms.djangoapps.utils import _get_key from .models import GeneratedCertificate @@ -25,6 +26,10 @@ def invalidate_certificate(self, user_id, course_key_or_id): Invalidate the user certificate in a given course if it exists. """ course_key = _get_key(course_key_or_id, CourseKey) + if CertificateWhitelist.objects.filter(user=user_id, course_id=course_key, whitelist=True).exists(): + log.info(f'User {user_id} is on the allowlist for {course_key}. The certificate will not be invalidated.') + return False + try: generated_certificate = GeneratedCertificate.objects.get( user=user_id, diff --git a/lms/djangoapps/certificates/signals.py b/lms/djangoapps/certificates/signals.py index eb0edf3e4e03..263a57cf5c47 100644 --- a/lms/djangoapps/certificates/signals.py +++ b/lms/djangoapps/certificates/signals.py @@ -85,6 +85,10 @@ def _listen_for_failing_grade(sender, user, course_id, grade, **kwargs): # pyli if it is currently passing, downstream signal from COURSE_GRADE_CHANGED """ + if CertificateWhitelist.objects.filter(user=user, course_id=course_id, whitelist=True).exists(): + log.info('{course_id} is using allowlist certificates, and the user {user_id} is on its allowlist. The ' + 'failing grade will not affect the certificate.'.format(course_id=course_id, user_id=user.id)) + return cert = GeneratedCertificate.certificate_for_student(user, course_id) if cert is not None: if CertificateStatuses.is_passing_status(cert.status):