diff --git a/MANIFEST.in b/MANIFEST.in index e2d565c9..feed15fc 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,4 +2,5 @@ include CHANGELOG.rst include LICENSE.txt include README.md include requirements/base.in +include requirements/eox-audit-model.in recursive-include eox_nelp *.html *.png *.gif *js *.css *jpg *jpeg *svg *py diff --git a/eox_nelp/course_experience/api/v1/views.py b/eox_nelp/course_experience/api/v1/views.py index 75a37dbc..feb55adb 100644 --- a/eox_nelp/course_experience/api/v1/views.py +++ b/eox_nelp/course_experience/api/v1/views.py @@ -51,6 +51,14 @@ ReportUnitExperienceSerializer, ) +try: + from eox_audit_model.decorators import audit_drf_api +except ImportError: + def audit_drf_api(*args, **kwargs): # pylint: disable=unused-argument + """Identity decorator""" + return lambda x: x + + INVALID_KEY_ERROR = { "error": "bad opaque key(item_id or course_id) `InvalidKeyError`" } @@ -106,6 +114,12 @@ def get_object(self): except InvalidKeyError as exc: raise Http404 from exc + @audit_drf_api( + action="eox-nelp-course-experience-api-v1-experienceviewset:create", + data_filter=["username", "item_id", "course_id"], + method_name="eox_nelp_audited_experience_create", + save_all_parameters=True, + ) def create(self, request, *args, **kwargs): """Perform processing for the request before use the base create method. Args: @@ -120,6 +134,12 @@ def create(self, request, *args, **kwargs): except InvalidKeyError as exc: raise ValidationError(INVALID_KEY_ERROR) from exc + @audit_drf_api( + action="eox-nelp-course-experience-api-v1-experienceviewset:update", + data_filter=["username", "item_id", "course_id"], + method_name="eox_nelp_audited_experience_update", + save_all_parameters=True, + ) def update(self, request, *args, **kwargs): """Perform processing for the request before use the base update method. Args: diff --git a/eox_nelp/settings/common.py b/eox_nelp/settings/common.py index 8dccfb8d..d18e09f9 100644 --- a/eox_nelp/settings/common.py +++ b/eox_nelp/settings/common.py @@ -10,6 +10,7 @@ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', + 'django.contrib.sites', 'django.contrib.sessions', 'social_django', 'eox_nelp', @@ -23,6 +24,7 @@ ) JSON_API_REST_FRAMEWORK = 'rest_framework_json_api' +EOX_AUDIT_MODEL_APP = 'eox_audit_model.apps.EoxAuditModelConfig' def plugin_settings(settings): @@ -52,3 +54,5 @@ def plugin_settings(settings): settings.INSTALLED_APPS.append(COURSE_CREATOR_APP) if find_spec(JSON_API_REST_FRAMEWORK) and JSON_API_REST_FRAMEWORK not in settings.INSTALLED_APPS: settings.INSTALLED_APPS.append(JSON_API_REST_FRAMEWORK) + if find_spec('eox_audit_model') and EOX_AUDIT_MODEL_APP not in settings.INSTALLED_APPS: + settings.INSTALLED_APPS.append(EOX_AUDIT_MODEL_APP) diff --git a/eox_nelp/settings/test.py b/eox_nelp/settings/test.py index 99ed07ce..1b35bc58 100644 --- a/eox_nelp/settings/test.py +++ b/eox_nelp/settings/test.py @@ -87,3 +87,9 @@ def plugin_settings(settings): # pylint: disable=function-redefined EOX_CORE_COURSEWARE_BACKEND = "eox_nelp.edxapp_wrapper.test_backends.courseware_m_v1" EOX_CORE_GRADES_BACKEND = "eox_nelp.edxapp_wrapper.test_backends.grades_m_v1" + +# ------------eox-audit external config for tests------------------------------ +if find_spec('eox_audit_model') and EOX_AUDIT_MODEL_APP not in INSTALLED_APPS: # noqa: F405 + INSTALLED_APPS.append(EOX_AUDIT_MODEL_APP) # noqa: F405 +ALLOW_EOX_AUDIT_MODEL = False +CELERY_TASK_ALWAYS_EAGER = True diff --git a/requirements/eox-audit-model.in b/requirements/eox-audit-model.in new file mode 100644 index 00000000..9d7504fd --- /dev/null +++ b/requirements/eox-audit-model.in @@ -0,0 +1,3 @@ +# Extra requirements + +eox-audit-model diff --git a/setup.py b/setup.py index 053d4049..bf00e822 100644 --- a/setup.py +++ b/setup.py @@ -89,6 +89,9 @@ def get_version(*file_paths): ], include_package_data=True, install_requires=load_requirements('requirements/base.in'), + extras_require={ + "eox-audit": load_requirements('requirements/eox-audit-model.in'), + }, zip_safe=False, entry_points={ "lms.djangoapp": [