From 93fd8cc14817f4fcf20b8aba2f59b9ca2f7639db Mon Sep 17 00:00:00 2001 From: Henrry Pulgarin <39854568+Henrrypg@users.noreply.github.com> Date: Wed, 30 Nov 2022 09:50:48 -0500 Subject: [PATCH 1/2] fix: prevent 500 error when course mode currency is not the same as the one configured in settings (#31312) This commit solves the http 500 error when course concurrency is setted different for PAID_COURSE_REGISTRATION_CURRENCY and course modes. --- common/djangoapps/course_modes/models.py | 5 ++++- common/djangoapps/course_modes/tests/test_models.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/course_modes/models.py b/common/djangoapps/course_modes/models.py index 0b015a133c..1cb7161fe2 100644 --- a/common/djangoapps/course_modes/models.py +++ b/common/djangoapps/course_modes/models.py @@ -774,7 +774,10 @@ class CourseMode(models.Model): If there is no mode found, will return the price of DEFAULT_MODE, which is 0 """ modes = cls.modes_for_course(course_id) - return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower()) + return min( + (mode.min_price for mode in modes if mode.currency.lower() == currency.lower()), + default=0 + ) @classmethod def is_eligible_for_certificate(cls, mode_slug, status=None): diff --git a/common/djangoapps/course_modes/tests/test_models.py b/common/djangoapps/course_modes/tests/test_models.py index 267b0259e1..9ce9e95c8e 100644 --- a/common/djangoapps/course_modes/tests/test_models.py +++ b/common/djangoapps/course_modes/tests/test_models.py @@ -125,6 +125,11 @@ class CourseModeModelTest(TestCase): # no modes, should get 0 assert 0 == CourseMode.min_course_price_for_currency(self.course_key, 'usd') + # with mode with other currency, should get 0 + mode = Mode('audit', 'Audit', 30, '', 'eur', None, None, None, None) + self.create_mode(mode.slug, mode.name, mode.min_price, mode.suggested_prices, mode.currency) + assert 0 == CourseMode.min_course_price_for_currency(self.course_key, 'usd') + # create some modes mode1 = Mode('honor', 'Honor Code Certificate', 10, '', 'usd', None, None, None, None) mode2 = Mode('verified', 'Verified Certificate', 20, '', 'usd', None, None, None, None) From 33968fb3763b451f5b8d09ea3dc2899f3a1b63fc Mon Sep 17 00:00:00 2001 From: Glib Glugovskiy Date: Wed, 30 Nov 2022 00:07:25 +0200 Subject: [PATCH 2/2] docs: ADR for signatures migration --- ...sfer-certificate-signatures-from-mongo.rst | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 lms/djangoapps/certificates/docs/decisions/007-transfer-certificate-signatures-from-mongo.rst diff --git a/lms/djangoapps/certificates/docs/decisions/007-transfer-certificate-signatures-from-mongo.rst b/lms/djangoapps/certificates/docs/decisions/007-transfer-certificate-signatures-from-mongo.rst new file mode 100644 index 0000000000..26803afe0c --- /dev/null +++ b/lms/djangoapps/certificates/docs/decisions/007-transfer-certificate-signatures-from-mongo.rst @@ -0,0 +1,120 @@ +Transfer certificate signatures to Credentials IDA +================================================== + +Status +------ +Accepted + +Context +------- +As a part of `Old Mongo Deprecation`_ work, we are planning to remove the support for c4x assets. +After removing the support for c4x assets from the ``StaticContentServer`` middleware, +the certificate signatures for ``Draft (Old) Mongo`` courses with deprecated IDs will become +unavailable. + +.. _`Old Mongo Deprecation`: https://github.com/openedx/public-engineering/issues/62 + +Decision +-------- +We will transfer and store certificate signatures in `Credentials`_ IDA and then use them to render HTML +certificates for ``Draft (Old) Mongo`` courses that have deprecated IDs. + +In order to transfer the signatures for ``Draft (Old) Mongo`` and ``Split Mongo`` courses, +it is necessary to complete the next tasks. + +* Extend credentials API to provide an option for adding and retrieving signatures. + + * ``CourseCertificateViewSet`` API should provide a possibility to optionally update + or create signatures for the course certificate. + + * ``CourseCertificateViewSet`` API should provide a list of signatures configured for a course certificate. + +* Add a new ``OpenEdxPublicSignal`` that is emitted from Studio whenever certificate-related data is changed + (e.g., certificate image upload, course import). The signature image can be exposed as a URL. + +* Create a signal receiver function, that will copy the certificate configuration including signatures images + to ``CourseCertificate`` model in Credentials using ``CourseCertificateViewSet`` API. + +* Add a new management command to copy course certificates configurations, + including signatures configuration and assets, from MongoDB to Credentials. + +* Update render certificate views to get signatures from Credentials + ``CourseCertificateViewSet`` for ``Draft (Old) Mongo`` courses only. + +Example of the certificate configuration stored in MongoDB: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. code-block:: json + + { + "certificates": { + "certificates": [ + { + "id": 853888039, + "name": "Name of the certificate", + "description": "Description of the certificate", + "is_active": true, + "version": 1, + "signatories": [ + { + "name": "Name", + "title": "Title", + "organization": "Organization", + "signature_image_path": "/c4x/ooniversity/DJ101/asset/png-transparent-circle-white-circle-white-monochrome-black-thumbnail.png", + "certificate": 853888039, + "id": 1300534915 + } + ], + "course_title": "cert" + } + ] + } + } + + +Credentials CourseCertificate model: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* site +* is_active +* signatories + + * Signatory fields: + + * name + * title + * organization_name_override + * image + +* title +* course_id +* course_run +* certificate_available_date +* certificate_type +* user_credentials + +.. _Credentials: https://github.com/openedx/credentials + +Consequences +------------ +* After implementing the new ``OpenEdxPublicSignal`` signal receiver, + every time the course or course certificate is updated, + certificate configuration including signatures configuration for + that course will be saved in ``CourseCertificate`` model in Credentials. +* During the certificate rendering, the certificate configuration fetched from MongoDB + will be merged with signatures configuration retrieved from Credentials. +* After transferring course certificates configurations from MongoDB to Credentials, + it would be easier to migrate certificates management from edx-platform to Credentials IDA. + + +Alternatives Considered +----------------------- +* `BD-11 Credentials Infrastructure + syncing`_ – suggests migrating course certificates + configuration to credentials and migrate course certificates frontend to MFEs. + +.. _`BD-11 Credentials Infrastructure + syncing`: https://github.com/openedx/credentials/issues/1734 + +References +--------------- +- `Migrate signature assets from MongoDB GridFS to the Credentials IDA `_ +- `[DEPR]: DraftModuleStore (Old Mongo Modulestore) `_ +- `Remove the ability to read and write static assets to Old Mongo `_ +