Skip to content

Commit

Permalink
feat: add eox-audit to course xp views
Browse files Browse the repository at this point in the history
feat: add optional eox-audit req

Also if audit is installed, the test settings are configured to continnue without
errors.

fix: add eox-audit-model in manifest.in
  • Loading branch information
johanseto committed Jun 9, 2023
1 parent 8a07da6 commit ef59bbb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions eox_nelp/course_experience/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
}
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions eox_nelp/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sites',
'django.contrib.sessions',
'social_django',
'eox_nelp',
Expand All @@ -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):
Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions eox_nelp/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions requirements/eox-audit-model.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Extra requirements

eox-audit-model
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit ef59bbb

Please sign in to comment.