From 58f47f3472931b03a1f6f2cb86e4f0784f32cb30 Mon Sep 17 00:00:00 2001 From: rahulkanneri-2u Date: Fri, 29 May 2026 17:17:36 +0530 Subject: [PATCH] feat: Move Program Certificate event publishing to the monolith --- lms/envs/common.py | 30 ++++++++++++++++ openedx/core/djangoapps/programs/tasks.py | 44 +++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/lms/envs/common.py b/lms/envs/common.py index 828c7874152b..89852ec73f60 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3218,6 +3218,36 @@ def _should_send_certificate_events(settings): "enabled": False }, }, + 'org.openedx.learning.program.certificate.awarded.v1': { + 'learning-program-certificate-lifecycle': { + 'event_key_field': 'program_certificate.program.uuid', + # .. toggle_name: EVENT_BUS_PRODUCER_CONFIG['org.openedx.learning.program.certificate.awarded.v1'] + # ['learning-program-certificate-lifecycle']['enabled'] + # .. toggle_implementation: DjangoSetting + # .. toggle_default: False + # .. toggle_description: Enables sending PROGRAM_CERTIFICATE_AWARDED events over the event bus from + # edx-platform. Disabled until Credentials IDA is ready to consume these events instead of + # receiving REST API calls. + # .. toggle_use_cases: opt_in + # .. toggle_creation_date: 2026-05-26 + 'enabled': False, + }, + }, + 'org.openedx.learning.program.certificate.revoked.v1': { + 'learning-program-certificate-lifecycle': { + 'event_key_field': 'program_certificate.program.uuid', + # .. toggle_name: EVENT_BUS_PRODUCER_CONFIG['org.openedx.learning.program.certificate.revoked.v1'] + # ['learning-program-certificate-lifecycle']['enabled'] + # .. toggle_implementation: DjangoSetting + # .. toggle_default: False + # .. toggle_description: Enables sending PROGRAM_CERTIFICATE_REVOKED events over the event bus from + # edx-platform. Disabled until Credentials IDA is ready to consume these events instead of + # receiving REST API calls. + # .. toggle_use_cases: opt_in + # .. toggle_creation_date: 2026-05-26 + 'enabled': False, + }, + }, }) #### Survey Report #### diff --git a/openedx/core/djangoapps/programs/tasks.py b/openedx/core/djangoapps/programs/tasks.py index 43dce6f392a3..b1674f18ce6c 100644 --- a/openedx/core/djangoapps/programs/tasks.py +++ b/openedx/core/djangoapps/programs/tasks.py @@ -30,6 +30,8 @@ ) from openedx.core.djangoapps.programs.utils import ProgramProgressMeter from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx_events.learning.data import ProgramCertificateData, ProgramData, UserData, UserPersonalData +from openedx_events.learning.signals import PROGRAM_CERTIFICATE_AWARDED, PROGRAM_CERTIFICATE_REVOKED from xmodule.data import CertificatesDisplayBehaviors if TYPE_CHECKING: @@ -364,6 +366,27 @@ def award_program_certificates(self, username): # pylint: disable=too-many-stat try: award_program_certificate(credentials_client, student, program_uuid) LOGGER.info(f"Awarded program certificate to user {student.id} in program {program_uuid}") + PROGRAM_CERTIFICATE_AWARDED.send_event( + program_certificate=ProgramCertificateData( + user=UserData( + pii=UserPersonalData( + username=student.username, + email=student.email, + name=student.profile.name, + ), + id=student.id, + is_active=student.is_active, + ), + program=ProgramData( + uuid=program_uuid, + title="", + program_type="", + ), + uuid="", + status="awarded", + url="", + ) + ) except HTTPError as exc: if exc.response.status_code == 404: LOGGER.warning( @@ -669,6 +692,27 @@ def revoke_program_certificates(self, username, course_key): # pylint: disable= try: revoke_program_certificate(credentials_client, username, program_uuid) LOGGER.info(f"Revoked program certificate from user {student.id} in program {program_uuid}") + PROGRAM_CERTIFICATE_REVOKED.send_event( + program_certificate=ProgramCertificateData( + user=UserData( + pii=UserPersonalData( + username=student.username, + email=student.email, + name=student.profile.name, + ), + id=student.id, + is_active=student.is_active, + ), + program=ProgramData( + uuid=program_uuid, + title="", + program_type="", + ), + uuid="", + status="revoked", + url="", + ) + ) except HTTPError as exc: if exc.response.status_code == 404: LOGGER.warning(