Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allows to audit the create_external_certificates method #84

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", {}),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These settings are general settings. Not a tenant aware.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings are settings tenant awareness depends on eox-tenant

}
return self.make_post(path, payload)

return self.make_post(path, payload)
return create_external_certificate_request(certificate_data)
Loading