From bab0b3930cf7761db146e24be819bb90249223fc Mon Sep 17 00:00:00 2001 From: NikolayBorovenskiy Date: Sun, 4 Dec 2022 17:42:50 +0200 Subject: [PATCH] feat: [EDXOLDMNG-218] Signals to save/delete certificate configuration for a course --- openedx_events/content_authoring/data.py | 54 +++++++++++++++++++ openedx_events/content_authoring/signals.py | 32 ++++++++++- .../event_bus/avro/tests/test_avro.py | 6 ++- 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/openedx_events/content_authoring/data.py b/openedx_events/content_authoring/data.py index 0c89d2dd..f9dcc872 100644 --- a/openedx_events/content_authoring/data.py +++ b/openedx_events/content_authoring/data.py @@ -8,6 +8,7 @@ (see deprecation proposal at https://github.com/openedx/public-engineering/issues/160) """ from datetime import datetime +from typing import BinaryIO, List import attr from opaque_keys.edx.keys import CourseKey, UsageKey @@ -82,3 +83,56 @@ class DuplicatedXBlockData(XBlockData): """ source_usage_key = attr.ib(type=UsageKey) + + +@attr.s(frozen=True) +class CertificateSignatoryData: + """ + Attributes defined for Open edX CertificateSignatory data object. + + Arguments: + image (BinaryIO): certificate signature image. + name (str): name of signatory. + organization (str): organization that signatory belongs to. + title (int): signatory title. + """ + + # Note: Please take care that the image field is BinaryIO, which means + # that a file can be passed as an array of bytes. Watch the size of this file. + # It can potentially be large, making it difficult to pass this data structure through the Event Bus + # (CloudEvent messages, which should be 64K or less) and store it on disk space. + # We suggest referring to MAX_ASSET_UPLOAD_FILE_SIZE_IN_MB, i.e. restriction in the Studio for such cases. + image = attr.ib(type=BinaryIO) + # end Note + name = attr.ib(type=str) + organization = attr.ib(type=str) + title = attr.ib(type=str) + + +@attr.s(frozen=True) +class CertificateConfigData: + """ + Attributes defined for Open edX CertificateConfig data object. + + Arguments: + certificate_type (str): certificate type. Possible types are certificate relevant course modes: + - credit, + - verified, + - professional, + - no-id-professional, + - executive-education, + - paid-executive-education, + - paid-bootcamp, + - masters. + course_key (CourseKey): identifier of the Course object. + title (str): certificate title. + signatories (List[CertificateSignatoryData]): contains a collection of signatures + that belong to the certificate configuration. + is_active (bool): indicates whether the certifivate configuration is active. + """ + + certificate_type = attr.ib(type=str) + course_key = attr.ib(type=CourseKey) + title = attr.ib(type=str) + signatories = attr.ib(type=List[CertificateSignatoryData], factory=list) + is_active = attr.ib(type=bool, default=False) diff --git a/openedx_events/content_authoring/signals.py b/openedx_events/content_authoring/signals.py index f0b85c04..8421cb8b 100644 --- a/openedx_events/content_authoring/signals.py +++ b/openedx_events/content_authoring/signals.py @@ -8,7 +8,12 @@ docs/decisions/0003-events-payload.rst """ -from openedx_events.content_authoring.data import CourseCatalogData, DuplicatedXBlockData, XBlockData +from openedx_events.content_authoring.data import ( + CertificateConfigData, + CourseCatalogData, + DuplicatedXBlockData, + XBlockData, +) from openedx_events.tooling import OpenEdxPublicSignal # .. event_type: org.openedx.content_authoring.course.catalog_info.changed.v1 @@ -62,3 +67,28 @@ "xblock_info": DuplicatedXBlockData, } ) + + +# .. event_type: org.openedx.content_authoring.course.certificate_config.changed.v1 +# .. event_name: COURSE_CERTIFICATE_CONFIG_CHANGED +# .. event_description: Fired when a course certificate configuration changes in Studio. +# Warning: This event is currently incompatible with the event bus, list/dict cannot be serialized yet +# .. event_data: CertificateConfigData +COURSE_CERTIFICATE_CONFIG_CHANGED = OpenEdxPublicSignal( + event_type="org.openedx.content_authoring.course.certificate_config.changed.v1", + data={ + "certificate_config": CertificateConfigData, + } +) + +# .. event_type: org.openedx.content_authoring.course.certificate_config.deleted.v1 +# .. event_name: COURSE_CERTIFICATE_CONFIG_DELETED +# .. event_description: Fired when a course certificate configuration deletes in Studio. +# Warning: This event is currently incompatible with the event bus, list/dict cannot be serialized yet +# .. event_data: CertificateConfigData +COURSE_CERTIFICATE_CONFIG_DELETED = OpenEdxPublicSignal( + event_type="org.openedx.content_authoring.course.certificate_config.deleted.v1", + data={ + "certificate_config": CertificateConfigData, + } +) diff --git a/openedx_events/event_bus/avro/tests/test_avro.py b/openedx_events/event_bus/avro/tests/test_avro.py index 6abd65e1..7f9b1f0a 100644 --- a/openedx_events/event_bus/avro/tests/test_avro.py +++ b/openedx_events/event_bus/avro/tests/test_avro.py @@ -26,7 +26,11 @@ # If a signal is explicitly not for use with the event bus, add it to this list # and document why in the event's annotations -KNOWN_UNSERIALIZABLE_SIGNALS = ["org.openedx.learning.discussions.configuration.changed.v1"] +KNOWN_UNSERIALIZABLE_SIGNALS = [ + "org.openedx.learning.discussions.configuration.changed.v1", + "org.openedx.content_authoring.course.certificate_config.changed.v1", + "org.openedx.content_authoring.course.certificate_config.deleted.v1", +] def generate_test_event_data_for_data_type(data_type):