Skip to content

Commit 3f7477b

Browse files
committed
Merge pull request #147 from eduNEXT/and/add_eox_audit_requirement
And/add eox audit requirement
2 parents 9236090 + eae43ad commit 3f7477b

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ Change Log
1111
.. There should always be an "Unreleased" section for changes pending release.
1212
Unreleased
1313
----------
14-
*
14+
15+
Added
16+
~~~~~
17+
* Decorate views that change or register some information.
18+
* Include eox-audit-model wrapper.
1519

1620
[4.9.0] - 2021-05-12
1721
--------------------

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ include README.rst
44
include requirements/base.in
55
include requirements/sentry.in
66
include requirements/tpa.in
7+
include requirements/eox-audit-model.in
78
recursive-include eox_core *.html *.png *.gif *js *.css *jpg *jpeg *svg *py
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Wrapper file for eox-audit-model"""
2+
from importlib import import_module, util
3+
4+
try:
5+
eox_audit_decorator = import_module('eox_audit_model.decorators')
6+
audit_method = eox_audit_decorator.audit_method
7+
except ImportError:
8+
pass
9+
10+
11+
def audit_api_wrapper(action='', data_filter=None):
12+
"""This decorator wraps the functionality of audit_method in order to
13+
work with django API view methods,also this allows to filter the data that will be
14+
stored in the data base.
15+
16+
Example
17+
18+
class YourAPIView(APIView):
19+
20+
@audit_api_wrapper(action='Get my items', data_filter=['username', 'location'])
21+
def get(self, request, *args, **kwargs):
22+
...
23+
"""
24+
def decorator(func):
25+
def wrapper(*args, **kwargs):
26+
if not util.find_spec('eox_audit_model'):
27+
return func(*args, **kwargs)
28+
29+
request = args[1]
30+
audit_data = request.data if request.data else request.query_params
31+
32+
if data_filter:
33+
audit_data = {key: value for key, value in audit_data.items() if key in data_filter}
34+
35+
@audit_method(action=action)
36+
def eox_core_api_method(audit_data):
37+
"""This method is just a wrapper in order to capture the input data"""
38+
return func(*args, **kwargs)
39+
40+
return eox_core_api_method(audit_data)
41+
42+
return wrapper
43+
44+
return decorator

eox_core/settings/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
from __future__ import absolute_import, unicode_literals
55

6+
from importlib.util import find_spec
7+
68
SECRET_KEY = 'a-not-to-be-trusted-secret-key'
79
INSTALLED_APPS = (
810
'django.contrib.auth',
@@ -12,6 +14,7 @@
1214
'django_filters',
1315
'oauth2_provider',
1416
)
17+
EOX_AUDIT_MODEL_APP = 'eox_audit_model.apps.EoxAuditModelConfig'
1518

1619

1720
def plugin_settings(settings):
@@ -71,3 +74,6 @@ def plugin_settings(settings):
7174
# has a match with the regex provided in the exc_text unique element. If exc_text contains more than one
7275
# regex, the exception is ignored if any of the regex matches the traceback text.
7376
settings.EOX_CORE_SENTRY_IGNORED_ERRORS = []
77+
78+
if find_spec('eox_audit_model') and EOX_AUDIT_MODEL_APP not in settings.INSTALLED_APPS:
79+
settings.INSTALLED_APPS.append(EOX_AUDIT_MODEL_APP)

requirements/eox-audit-model.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Extra requirements
2+
3+
eox-audit-model

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def is_requirement(line):
7272
install_requires=load_requirements('requirements/base.in'),
7373
extras_require={
7474
"sentry": load_requirements('requirements/sentry.in'),
75-
"tpa": load_requirements('requirements/tpa.in')
75+
"tpa": load_requirements('requirements/tpa.in'),
76+
"eox-audit": load_requirements('requirements/eox-audit-model.in')
7677
},
7778
scripts=[],
7879
license="AGPL",

0 commit comments

Comments
 (0)