Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Feature/logging username #11

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

## [unreleased - 03-12-2021]
- Allow `username` logging when user is authenticated

## 0.4.0 (29-01-2020)

### Note worthy changes
Expand Down
1 change: 1 addition & 0 deletions src/django_audit_log/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def set_user_from_request(
email=getattr(user, 'email', '') if user else '',
roles=roles,
ip=get_client_ip(request),
username=request.user.username if user and user.is_authenticated else '',
)
return self

Expand Down
2 changes: 2 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_set_user_from_request(self):
self.assertEqual(audit_log.user['email'], '[email protected]')
self.assertEqual(audit_log.user['roles'], ['testgroup'])
self.assertEqual(audit_log.user['ip'], '127.0.0.1')
self.assertEqual(audit_log.user['username'], 'username')

def test_extras_user_from_request(self):
user = User.objects.create_user(username='username', email='[email protected]')
Expand All @@ -97,6 +98,7 @@ def test_extras_user_from_request(self):
self.assertEqual(extras['user']['email'], '[email protected]')
self.assertEqual(extras['user']['roles'], ['testgroup'])
self.assertEqual(extras['user']['ip'], '127.0.0.1')
self.assertEqual(extras['user']['username'], 'username')

def test_get_headers_from_response(self):
expected_headers = {
Expand Down