Skip to content

Commit c27db1e

Browse files
authored
Merge pull request #64 from lorenzomorandini/whitelist_request_signals
Implemented auditing of ONLY REGISTERED_URLS
2 parents 99de05a + 4983ea5 commit c27db1e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

easyaudit/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def get_model_list(class_list):
6060
UNREGISTERED_URLS.extend(getattr(settings, 'DJANGO_EASY_AUDIT_UNREGISTERED_URLS_EXTRA', []))
6161

6262

63+
# URLs which Django Easy Audit WILL log.
64+
# If the following setting is defined in the project,
65+
# only the listed URLs will be audited, and every other
66+
# URL will be excluded.
67+
REGISTERED_URLS = getattr(settings, 'DJANGO_EASY_AUDIT_REGISTERED_URLS', [])
68+
69+
6370
# By default all modules are listed in the admin.
6471
# This can be changed with the following settings.
6572
ADMIN_SHOW_MODEL_EVENTS = getattr(settings, 'DJANGO_EASY_AUDIT_ADMIN_SHOW_MODEL_EVENTS', True)

easyaudit/signals/request_signals.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.conf import settings
77

88
from easyaudit.models import RequestEvent
9-
from easyaudit.settings import REMOTE_ADDR_HEADER, UNREGISTERED_URLS, WATCH_REQUEST_EVENTS
9+
from easyaudit.settings import REMOTE_ADDR_HEADER, UNREGISTERED_URLS, REGISTERED_URLS, WATCH_REQUEST_EVENTS
1010

1111
import re
1212

@@ -17,6 +17,16 @@ def should_log_url(url):
1717
pattern = re.compile(unregistered_url)
1818
if pattern.match(url):
1919
return False
20+
21+
# only audit URLs listed in REGISTERED_URLS (if it's set)
22+
if len(REGISTERED_URLS) > 0:
23+
for registered_url in REGISTERED_URLS:
24+
pattern = re.compile(registered_url)
25+
if pattern.match(url):
26+
return True
27+
return False
28+
29+
# all good
2030
return True
2131

2232

0 commit comments

Comments
 (0)