Skip to content

Commit

Permalink
Merge pull request #84 from eduNEXT/and/audit_certificates_api_client
Browse files Browse the repository at this point in the history
feat: allows to audit the create_external_certificates method
  • Loading branch information
andrey-canon committed Aug 10, 2023
2 parents 8c9bb65 + 797c944 commit fd90b14
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions eox_nelp/api_clients/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

from eox_nelp.api_clients import AbstractBasicAuthApiClient

try:
from eox_audit_model.decorators import audit_method
except ImportError:
def audit_method(action): # pylint: disable=unused-argument
"""Identity audit_method"""
return lambda x: x


class ExternalCertificatesApiClient(AbstractBasicAuthApiClient):
"""Allow to perform multiple external certificates operations."""
Expand Down Expand Up @@ -46,27 +53,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)

0 comments on commit fd90b14

Please sign in to comment.