From 0b22c702488ac4e8bebc0152895efa5325b4d59c Mon Sep 17 00:00:00 2001 From: Justin Hynes Date: Mon, 15 Mar 2021 12:00:26 -0400 Subject: [PATCH] MICROBA-1011 | Reduce use of Certificates models accessed directly in Instructor Dashboard djangoapp [MICROBA-1011] - When creating bulk allowlist entries make the tool use the `is_on_allowlist` certificate API function over accessing the CertificateWhitelist model methods directly - When creating bulk allowlist entries make the tool use the `create_or_update_allowlist_entry` certificate API function over using CertificateWhitelist model/Django ORM directly --- lms/djangoapps/instructor/views/api.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 6fc9cedf89..d5bc241267 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -71,8 +71,7 @@ from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled from lms.djangoapps.bulk_email.models import CourseEmail from lms.djangoapps.certificates import api as certs_api from lms.djangoapps.certificates.models import ( - CertificateStatuses, - CertificateWhitelist + CertificateStatuses ) from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.courses import get_course_by_id, get_course_with_access @@ -2849,7 +2848,7 @@ def generate_bulk_certificate_exceptions(request, course_id): build_row_errors('user_on_certificate_invalidation_list', user, row_num) log.warning(f'Student {user.id} is blocked from receiving a Certificate in Course {course_key}') # make sure user isn't already on the exception list - elif CertificateWhitelist.get_certificate_white_list(course_key, user): + elif certs_api.is_on_allowlist(user, course_key): build_row_errors('user_already_white_listed', user, row_num) log.warning(f'Student {user.id} already on exception list in Course {course_key}.') # make sure user is enrolled in course @@ -2857,10 +2856,9 @@ def generate_bulk_certificate_exceptions(request, course_id): build_row_errors('user_not_enrolled', user, row_num) log.warning(f'Student {user.id} is not enrolled in Course {course_key}') else: - CertificateWhitelist.objects.create( - user=user, - course_id=course_key, - whitelist=True, + certs_api.create_or_update_certificate_allowlist_entry( + user, + course_key, notes=student[notes_index] ) success.append(_('user "{username}" in row# {row}').format(username=user.username, row=row_num))