MICROBA-1032 Add allowlist check and move tests (#26785)

This commit is contained in:
Christie Rice
2021-03-02 14:04:03 -05:00
committed by GitHub
parent 0846e04f45
commit e5872cf8f2
2 changed files with 13 additions and 7 deletions

View File

@@ -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()