Skip to content

Commit

Permalink
feat: allows to audit the create_external_certificates method
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-canon committed Aug 10, 2023
1 parent 7f0fb34 commit b617c3a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 43 deletions.
51 changes: 28 additions & 23 deletions eox_nelp/api_clients/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"nelc-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"nelc-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)
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 18 additions & 9 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -74,6 +75,7 @@ django==3.2.20
# edx-i18n-tools
# edx-proctoring
# edx-when
# eox-audit-model
# eox-core
# eox-theming
# event-tracking
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions requirements/pip-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ 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
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:
Expand Down
21 changes: 14 additions & 7 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -111,6 +112,7 @@ django==3.2.20
# edx-i18n-tools
# edx-proctoring
# edx-when
# eox-audit-model
# eox-core
# eox-theming
# event-tracking
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements/tox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit b617c3a

Please sign in to comment.