From 143eeea9ba255384a59189ea46954d4fee8f583c Mon Sep 17 00:00:00 2001 From: andrey-canon Date: Thu, 10 Aug 2023 13:21:09 -0500 Subject: [PATCH] feat: allows to audit the create_external_certificates method --- eox_nelp/api_clients/certificates.py | 51 +++++++++++++++------------- requirements/base.in | 1 + requirements/base.txt | 27 ++++++++++----- requirements/pip-tools.txt | 5 +-- requirements/test.txt | 21 ++++++++---- requirements/tox.txt | 4 +-- 6 files changed, 66 insertions(+), 43 deletions(-) diff --git a/eox_nelp/api_clients/certificates.py b/eox_nelp/api_clients/certificates.py index 3f2bc3eb..544af1cd 100644 --- a/eox_nelp/api_clients/certificates.py +++ b/eox_nelp/api_clients/certificates.py @@ -4,6 +4,7 @@ ExternalCertificatesApiClient: Class to interact with NELP external certificates service. """ from django.conf import settings +from eox_audit_model.decorators import audit_method from eox_nelp.api_clients import AbstractBasicAuthApiClient @@ -46,27 +47,31 @@ def create_external_certificate(self, certificate_data): Raise: KeyError: This will be raised when the mandatory are excluded in the certificate data. """ - path = "Certificates" - user = certificate_data["user"] - payload = { - "reference_id": f"openedx-lms-cert-{certificate_data['id']}", - "date": { - "issuance": certificate_data["created_at"], - "expiration": None, - }, - "individual": { - "name_en": user["english_name"], - "name_ar": user["arabic_name"], - "id": user["national_id"], - "id_type": "saudi", - }, - "group_code": certificate_data["group_code"], - "certificate_type": "completion", # What types do we have ? - "score": { - "value": certificate_data["grade"], - "type": "percentage" - }, - "metadata": getattr(settings, "EXTERNAL_CERTIFICATES_METADATA", {}), - } + @audit_method(action="Create External Certificate") + def create_external_certificate_request(certificate_data): + """This is a wrapper that allows to make audit-able the create_external_certificate method.""" + path = "Certificates" + user = certificate_data["user"] + payload = { + "reference_id": f"openedx-lms-cert-{certificate_data['id']}", + "date": { + "issuance": certificate_data["created_at"], + "expiration": None, + }, + "individual": { + "name_en": user["english_name"], + "name_ar": user["arabic_name"], + "id": user["national_id"], + "id_type": "saudi", + }, + "group_code": certificate_data["group_code"], + "certificate_type": "completion", # What types do we have ? + "score": { + "value": certificate_data["grade"], + "type": "percentage" + }, + "metadata": getattr(settings, "EXTERNAL_CERTIFICATES_METADATA", {}), + } + return self.make_post(path, payload) - return self.make_post(path, payload) + return create_external_certificate_request(certificate_data) diff --git a/requirements/base.in b/requirements/base.in index 43ffa456..9c1e8b23 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -9,6 +9,7 @@ djangorestframework-jsonapi==5.0.0 edx-drf-extensions edx-i18n-tools edx-opaque-keys +eox-audit-model eox-core eox-tenant eox-theming diff --git a/requirements/base.txt b/requirements/base.txt index 2187d5d5..15d0fe63 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -20,6 +20,7 @@ bs4==0.0.1 # via -r requirements/base.in celery==5.3.1 # via + # eox-audit-model # eox-core # event-tracking certifi==2023.7.22 @@ -44,7 +45,7 @@ click-plugins==1.1.1 # via celery click-repl==0.3.0 # via celery -cryptography==41.0.2 +cryptography==41.0.3 # via # jwcrypto # pyjwt @@ -74,6 +75,7 @@ django==3.2.20 # edx-i18n-tools # edx-proctoring # edx-when + # eox-audit-model # eox-core # eox-theming # event-tracking @@ -84,13 +86,16 @@ django-crum==0.7.9 # via # edx-django-utils # edx-proctoring + # eox-audit-model django-filter==21.1 # via # -c requirements/constraints.txt # -r requirements/base.in # eox-core django-ipware==5.0.0 - # via edx-proctoring + # via + # edx-proctoring + # eox-audit-model django-model-utils==4.3.1 # via # edx-proctoring @@ -130,7 +135,7 @@ drf-yasg==1.21.7 # via edx-api-doc-tools edx-api-doc-tools==1.7.0 # via eox-core -edx-django-utils==5.6.0 +edx-django-utils==5.7.0 # via # edx-drf-extensions # edx-rest-api-client @@ -142,7 +147,7 @@ edx-drf-extensions==8.0.0 # -r requirements/base.in # edx-proctoring # edx-when -edx-i18n-tools==1.0.0 +edx-i18n-tools==1.1.0 # via -r requirements/base.in edx-opaque-keys[django]==2.3.0 # via @@ -152,12 +157,14 @@ edx-opaque-keys[django]==2.3.0 # edx-when # eox-core # openedx-events -edx-proctoring==4.16.0 +edx-proctoring==4.16.1 # via eox-core edx-rest-api-client==5.6.0 # via edx-proctoring edx-when==2.4.0 # via edx-proctoring +eox-audit-model==2.0.0 + # via -r requirements/base.in eox-core==8.1.0 # via -r requirements/base.in eox-tenant==9.2.1 @@ -166,7 +173,7 @@ eox-tenant==9.2.1 # eox-theming eox-theming==5.0.0 # via -r requirements/base.in -event-tracking==2.1.0 +event-tracking==2.2.0 # via edx-proctoring fastavro==1.8.2 # via openedx-events @@ -181,7 +188,9 @@ inflection==0.5.1 # djangorestframework-jsonapi # drf-yasg jsonfield==3.1.0 - # via edx-proctoring + # via + # edx-proctoring + # eox-audit-model jwcrypto==1.5.0 # via django-oauth-toolkit kombu==5.3.1 @@ -315,13 +324,13 @@ vine==5.0.0 # kombu wcwidth==0.2.6 # via prompt-toolkit -web-fragments==2.0.0 +web-fragments==2.1.0 # via xblock webob==1.8.7 # via xblock wrapt==1.15.0 # via deprecated -xblock==1.6.2 +xblock==1.7.0 # via edx-when # The following packages are considered to be unsafe in a requirements file: diff --git a/requirements/pip-tools.txt b/requirements/pip-tools.txt index 759456d5..def0a828 100644 --- a/requirements/pip-tools.txt +++ b/requirements/pip-tools.txt @@ -10,7 +10,7 @@ click==8.1.6 # via pip-tools packaging==23.1 # via build -pip-tools==7.1.0 +pip-tools==7.3.0 # via -r requirements/pip-tools.in pyproject-hooks==1.0.0 # via build @@ -18,7 +18,8 @@ tomli==2.0.1 # via # build # pip-tools -wheel==0.41.0 + # pyproject-hooks +wheel==0.41.1 # via pip-tools # The following packages are considered to be unsafe in a requirements file: diff --git a/requirements/test.txt b/requirements/test.txt index 441362c6..4fd78dd1 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -35,6 +35,7 @@ bs4==0.0.1 celery==5.3.1 # via # -r requirements/base.txt + # eox-audit-model # eox-core # event-tracking certifi==2023.7.22 @@ -73,7 +74,7 @@ click-repl==0.3.0 # celery coverage==7.2.7 # via -r requirements/test.in -cryptography==41.0.2 +cryptography==41.0.3 # via # -r requirements/base.txt # jwcrypto @@ -111,6 +112,7 @@ django==3.2.20 # edx-i18n-tools # edx-proctoring # edx-when + # eox-audit-model # eox-core # eox-theming # event-tracking @@ -122,6 +124,7 @@ django-crum==0.7.9 # -r requirements/base.txt # edx-django-utils # edx-proctoring + # eox-audit-model django-fake-model==0.1.4 # via -r requirements/test.in django-filter==21.1 @@ -133,6 +136,7 @@ django-ipware==5.0.0 # via # -r requirements/base.txt # edx-proctoring + # eox-audit-model django-model-utils==4.3.1 # via # -r requirements/base.txt @@ -188,7 +192,7 @@ edx-api-doc-tools==1.7.0 # via # -r requirements/base.txt # eox-core -edx-django-utils==5.6.0 +edx-django-utils==5.7.0 # via # -r requirements/base.txt # edx-drf-extensions @@ -201,7 +205,7 @@ edx-drf-extensions==8.0.0 # -r requirements/base.txt # edx-proctoring # edx-when -edx-i18n-tools==1.0.0 +edx-i18n-tools==1.1.0 # via -r requirements/base.txt edx-opaque-keys[django]==2.3.0 # via @@ -211,7 +215,7 @@ edx-opaque-keys[django]==2.3.0 # edx-when # eox-core # openedx-events -edx-proctoring==4.16.0 +edx-proctoring==4.16.1 # via # -r requirements/base.txt # eox-core @@ -223,6 +227,8 @@ edx-when==2.4.0 # via # -r requirements/base.txt # edx-proctoring +eox-audit-model==2.0.0 + # via -r requirements/base.txt eox-core==8.1.0 # via -r requirements/base.txt eox-tenant==9.2.1 @@ -231,7 +237,7 @@ eox-tenant==9.2.1 # eox-theming eox-theming==5.0.0 # via -r requirements/base.txt -event-tracking==2.1.0 +event-tracking==2.2.0 # via # -r requirements/base.txt # edx-proctoring @@ -264,6 +270,7 @@ jsonfield==3.1.0 # via # -r requirements/base.txt # edx-proctoring + # eox-audit-model jwcrypto==1.5.0 # via # -r requirements/base.txt @@ -489,7 +496,7 @@ wcwidth==0.2.6 # via # -r requirements/base.txt # prompt-toolkit -web-fragments==2.0.0 +web-fragments==2.1.0 # via # -r requirements/base.txt # xblock @@ -502,7 +509,7 @@ wrapt==1.15.0 # -r requirements/base.txt # astroid # deprecated -xblock==1.6.2 +xblock==1.7.0 # via # -r requirements/base.txt # edx-when diff --git a/requirements/tox.txt b/requirements/tox.txt index 408bd04e..d25c37a7 100644 --- a/requirements/tox.txt +++ b/requirements/tox.txt @@ -6,7 +6,7 @@ # cachetools==5.3.1 # via tox -chardet==5.1.0 +chardet==5.2.0 # via tox colorama==0.4.6 # via tox @@ -32,7 +32,7 @@ tomli==2.0.1 # via # pyproject-api # tox -tox==4.6.4 +tox==4.7.0 # via -r requirements/tox.in virtualenv==20.24.2 # via tox