diff --git a/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py b/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py index 533082de6ac5593dac6ca9df915d0867ae199e19..d455860a8762ee901d6c9ae323e659f5bc016ea7 100644 --- a/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py +++ b/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py @@ -7,6 +7,7 @@ import logging from django.core.management.base import BaseCommand +from lms.djangoapps.certificates.api import is_using_certificate_allowlist_and_is_on_allowlist from lms.djangoapps.certificates.models import GeneratedCertificate from lms.djangoapps.courseware import courses from lms.djangoapps.grades.api import CourseGradeFactory @@ -16,7 +17,8 @@ log = logging.getLogger(__name__) class Command(BaseCommand): """ - Management command to find and grade all students that need to be graded. + Management command to find and grade all students that need to be graded, unless the user is on the allowlist + for that course run. """ help = """ @@ -50,9 +52,13 @@ class Command(BaseCommand): ).filter(grade__exact='') course = courses.get_course_by_id(course_id) for cert in ungraded: - # grade the student - grade = CourseGradeFactory().read(cert.user, course) - log.info('grading %s - %s', cert.user, grade.percent) - cert.grade = grade.percent - if not options['noop']: - cert.save() + if is_using_certificate_allowlist_and_is_on_allowlist(cert.user, course_id): + log.info(f'{course_id} is using allowlist certificates, and the user {cert.user.id} is on its ' + f'allowlist. Certificate will not be regraded') + else: + # grade the student + grade = CourseGradeFactory().read(cert.user, course) + log.info('grading %s - %s', cert.user, grade.percent) + cert.grade = grade.percent + if not options['noop']: + cert.save() diff --git a/lms/djangoapps/certificates/tests/test_cert_management.py b/lms/djangoapps/certificates/management/commands/tests/test_cert_management.py similarity index 100% rename from lms/djangoapps/certificates/tests/test_cert_management.py rename to lms/djangoapps/certificates/management/commands/tests/test_cert_management.py