From 1088b947a87e89f1b04e439bd8f34ca6ab88c18b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 17 Oct 2020 22:26:18 +0200 Subject: [PATCH] audit: remove duplicate date column, add search --- docs/installation/docker-compose.md | 4 +- docs/upgrading/to-0.12.md | 1 + .../migrations/0006_auto_20201017_2024.py | 42 +++++++++++++++++++ passbook/audit/models.py | 3 +- passbook/audit/templates/audit/list.html | 1 + passbook/audit/views.py | 16 ++++++- 6 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 passbook/audit/migrations/0006_auto_20201017_2024.py diff --git a/docs/installation/docker-compose.md b/docs/installation/docker-compose.md index 167209401..03f402438 100644 --- a/docs/installation/docker-compose.md +++ b/docs/installation/docker-compose.md @@ -4,8 +4,8 @@ This installation method is for test-setups and small-scale productive setups. ## Prerequisites -- docker -- docker-compose +- docker +- docker-compose ## Install diff --git a/docs/upgrading/to-0.12.md b/docs/upgrading/to-0.12.md index 9243fc03c..8c2407de8 100644 --- a/docs/upgrading/to-0.12.md +++ b/docs/upgrading/to-0.12.md @@ -6,6 +6,7 @@ This update brings these headline features: - Add Kubernetes Integration for Outposts, which deploys and maintains Outposts with High Availability in a Kubernetes Cluster - Add System Task Overview to see all background tasks, their status, the log output, and retry them - Alerts now disappear automatically +- Audit Logs are now searchable Fixes: diff --git a/passbook/audit/migrations/0006_auto_20201017_2024.py b/passbook/audit/migrations/0006_auto_20201017_2024.py new file mode 100644 index 000000000..89a0fdc5b --- /dev/null +++ b/passbook/audit/migrations/0006_auto_20201017_2024.py @@ -0,0 +1,42 @@ +# Generated by Django 3.1.2 on 2020-10-17 20:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_audit", "0005_auto_20201005_2139"), + ] + + operations = [ + migrations.RemoveField( + model_name="event", + name="date", + ), + migrations.AlterField( + model_name="event", + name="action", + field=models.TextField( + choices=[ + ("login", "Login"), + ("login_failed", "Login Failed"), + ("logout", "Logout"), + ("user_write", "User Write"), + ("suspicious_request", "Suspicious Request"), + ("password_set", "Password Set"), + ("token_view", "Token View"), + ("invitation_created", "Invite Created"), + ("invitation_used", "Invite Used"), + ("authorize_application", "Authorize Application"), + ("source_linked", "Source Linked"), + ("impersonation_started", "Impersonation Started"), + ("impersonation_ended", "Impersonation Ended"), + ("model_created", "Model Created"), + ("model_updated", "Model Updated"), + ("model_deleted", "Model Deleted"), + ("custom_", "Custom Prefix"), + ] + ), + ), + ] diff --git a/passbook/audit/models.py b/passbook/audit/models.py index a6b37a648..c589a5349 100644 --- a/passbook/audit/models.py +++ b/passbook/audit/models.py @@ -100,6 +100,8 @@ class EventAction(models.TextChoices): SUSPICIOUS_REQUEST = "suspicious_request" PASSWORD_SET = "password_set" # noqa # nosec + TOKEN_VIEW = "token_view" + INVITE_CREATED = "invitation_created" INVITE_USED = "invitation_used" @@ -122,7 +124,6 @@ class Event(models.Model): event_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4) user = models.JSONField(default=dict) action = models.TextField(choices=EventAction.choices) - date = models.DateTimeField(auto_now_add=True) app = models.TextField() context = models.JSONField(default=dict, blank=True) client_ip = models.GenericIPAddressField(null=True) diff --git a/passbook/audit/templates/audit/list.html b/passbook/audit/templates/audit/list.html index 214ab744e..744f4d815 100644 --- a/passbook/audit/templates/audit/list.html +++ b/passbook/audit/templates/audit/list.html @@ -17,6 +17,7 @@
+ {% include 'partials/toolbar_search.html' %} {% include 'partials/pagination.html' %}
diff --git a/passbook/audit/views.py b/passbook/audit/views.py index ba32ba6d9..e08d5c2f7 100644 --- a/passbook/audit/views.py +++ b/passbook/audit/views.py @@ -3,12 +3,16 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import ListView from guardian.mixins import PermissionListMixin -from passbook.admin.views.utils import UserPaginateListMixin +from passbook.admin.views.utils import SearchListMixin, UserPaginateListMixin from passbook.audit.models import Event class EventListView( - PermissionListMixin, LoginRequiredMixin, UserPaginateListMixin, ListView + PermissionListMixin, + LoginRequiredMixin, + SearchListMixin, + UserPaginateListMixin, + ListView, ): """Show list of all invitations""" @@ -16,3 +20,11 @@ class EventListView( template_name = "audit/list.html" permission_required = "passbook_audit.view_event" ordering = "-created" + + search_fields = [ + "user", + "action", + "app", + "context", + "client_ip", + ]