From 25eb2238c5cf3a2ca103078032ffb2978d95b94d Mon Sep 17 00:00:00 2001 From: Dmytro <98233552+DmytroAlipov@users.noreply.github.com> Date: Wed, 10 Apr 2024 21:58:34 +0200 Subject: [PATCH] feat: add ability to notify credentials about honor certificates (#34485) Co-authored-by: Dima Alipov --- .../djangoapps/credentials/tasks/v1/tasks.py | 16 +++++++++++++--- openedx/core/djangoapps/programs/tasks.py | 10 ++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/openedx/core/djangoapps/credentials/tasks/v1/tasks.py b/openedx/core/djangoapps/credentials/tasks/v1/tasks.py index dad4d3618a97..ae0a3da8ae92 100644 --- a/openedx/core/djangoapps/credentials/tasks/v1/tasks.py +++ b/openedx/core/djangoapps/credentials/tasks/v1/tasks.py @@ -373,7 +373,11 @@ def send_grade_if_interesting( # Don't worry about whether it's available as well as awarded. Just awarded is good enough to record a verified # attempt at a course. We want even the grades that didn't pass the class because Credentials wants to know about # those too. - if mode not in INTERESTING_MODES or status not in INTERESTING_STATUSES: + if ( + mode not in INTERESTING_MODES + and not CourseMode.is_eligible_for_certificate(mode) + or status not in INTERESTING_STATUSES + ): if verbose: logger.info(f"Skipping send grade: mode/status uninteresting for mode [{mode}] & status [{status}]") return @@ -452,7 +456,10 @@ def backfill_date_for_all_course_runs(): course_key = str(course_run.id) course_modes = CourseMode.objects.filter(course_id=course_key) # There should only ever be one certificate relevant mode per course run - modes = [mode.slug for mode in course_modes if mode.slug in CourseMode.CERTIFICATE_RELEVANT_MODES] + modes = [ + mode.slug for mode in course_modes + if mode.slug in CourseMode.CERTIFICATE_RELEVANT_MODES or CourseMode.is_eligible_for_certificate(mode.slug) + ] if len(modes) != 1: logger.exception( f'Either course {course_key} has no certificate mode or multiple modes. Task failed.' @@ -503,7 +510,10 @@ def clean_certificate_available_date(): course_key = str(course_run.id) course_modes = CourseMode.objects.filter(course_id=course_key) # There should only ever be one certificate relevant mode per course run - modes = [mode.slug for mode in course_modes if mode.slug in CourseMode.CERTIFICATE_RELEVANT_MODES] + modes = [ + mode.slug for mode in course_modes + if mode.slug in CourseMode.CERTIFICATE_RELEVANT_MODES or CourseMode.is_eligible_for_certificate(mode.slug) + ] if len(modes) != 1: logger.exception(f'Either course {course_key} has no certificate mode or multiple modes. Task failed.') # if there is only one relevant mode, post to credentials diff --git a/openedx/core/djangoapps/programs/tasks.py b/openedx/core/djangoapps/programs/tasks.py index a22bff876de4..0a23be073b50 100644 --- a/openedx/core/djangoapps/programs/tasks.py +++ b/openedx/core/djangoapps/programs/tasks.py @@ -384,7 +384,10 @@ def update_credentials_course_certificate_configuration_available_date( course_key = str(course_key) course_modes = CourseMode.objects.filter(course_id=course_key) # There should only ever be one certificate relevant mode per course run - modes = [mode.slug for mode in course_modes if mode.slug in CourseMode.CERTIFICATE_RELEVANT_MODES] + modes = [ + mode.slug for mode in course_modes + if mode.slug in CourseMode.CERTIFICATE_RELEVANT_MODES or CourseMode.is_eligible_for_certificate(mode.slug) + ] if len(modes) != 1: LOGGER.exception( f'Either course {course_key} has no certificate mode or multiple modes. Task failed.' @@ -471,7 +474,10 @@ def _retry_with_custom_exception(username, course_run_key, reason, countdown): f"for {course_key} to user {username}" ) return - if certificate.mode in CourseMode.CERTIFICATE_RELEVANT_MODES: + if ( + certificate.mode in CourseMode.CERTIFICATE_RELEVANT_MODES + or CourseMode.is_eligible_for_certificate(certificate.mode) + ): try: course_overview = CourseOverview.get_from_id(course_key) except (CourseOverview.DoesNotExist, OSError):