*: use Audit custom event action, add SOURCE_LINKED event action

This commit is contained in:
Jens Langhammer 2020-09-21 20:30:30 +02:00
parent dbcdab05ff
commit 945d5bfaf6
8 changed files with 51 additions and 12 deletions

View File

@ -0,0 +1,37 @@
# Generated by Django 3.1.1 on 2020-09-21 18:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("passbook_audit", "0003_auto_20200917_1155"),
]
operations = [
migrations.AlterField(
model_name="event",
name="action",
field=models.TextField(
choices=[
("login", "Login"),
("login_failed", "Login Failed"),
("logout", "Logout"),
("sign_up", "Sign Up"),
("authorize_application", "Authorize Application"),
("suspicious_request", "Suspicious Request"),
("password_set", "Password Set"),
("invitation_created", "Invite Created"),
("invitation_used", "Invite Used"),
("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"),
]
),
),
]

View File

@ -104,6 +104,8 @@ class EventAction(models.TextChoices):
INVITE_CREATED = "invitation_created" INVITE_CREATED = "invitation_created"
INVITE_USED = "invitation_used" INVITE_USED = "invitation_used"
SOURCE_LINKED = "source_linked"
IMPERSONATION_STARTED = "impersonation_started" IMPERSONATION_STARTED = "impersonation_started"
IMPERSONATION_ENDED = "impersonation_ended" IMPERSONATION_ENDED = "impersonation_ended"

View File

@ -57,9 +57,7 @@ def on_user_logged_out(sender, request: HttpRequest, user: User, **_):
# pylint: disable=unused-argument # pylint: disable=unused-argument
def on_user_write(sender, request: HttpRequest, user: User, data: Dict[str, Any], **_): def on_user_write(sender, request: HttpRequest, user: User, data: Dict[str, Any], **_):
"""Log User write""" """Log User write"""
thread = EventNewThread( thread = EventNewThread("stages/user_write", request, **data)
EventAction.CUSTOM, request, caller="stages/user_write", **data
)
thread.user = user thread.user = user
thread.run() thread.run()

View File

@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType
from django.test import TestCase from django.test import TestCase
from guardian.shortcuts import get_anonymous_user from guardian.shortcuts import get_anonymous_user
from passbook.audit.models import Event, EventAction from passbook.audit.models import Event
from passbook.policies.dummy.models import DummyPolicy from passbook.policies.dummy.models import DummyPolicy

View File

@ -182,7 +182,7 @@ class OAuthCallback(OAuthClientMixin, View):
access.save() access.save()
UserOAuthSourceConnection.objects.filter(pk=access.pk).update(user=user) UserOAuthSourceConnection.objects.filter(pk=access.pk).update(user=user)
Event.new( Event.new(
EventAction.CUSTOM, message="Linked OAuth Source", source=source EventAction.SOURCE_LINKED, message="Linked OAuth Source", source=source
).from_http(self.request) ).from_http(self.request)
messages.success( messages.success(
self.request, self.request,

View File

@ -23,6 +23,8 @@ class PostUserEnrollmentStage(StageView):
access.save() access.save()
UserOAuthSourceConnection.objects.filter(pk=access.pk).update(user=user) UserOAuthSourceConnection.objects.filter(pk=access.pk).update(user=user)
Event.new( Event.new(
EventAction.CUSTOM, message="Linked OAuth Source", source=access.source EventAction.SOURCE_LINKED,
message="Linked OAuth Source",
source=access.source,
).from_http(self.request) ).from_http(self.request)
return self.executor.stage_ok() return self.executor.stage_ok()

View File

@ -7,7 +7,7 @@ from django.views import View
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django_otp.plugins.otp_static.models import StaticDevice, StaticToken from django_otp.plugins.otp_static.models import StaticDevice, StaticToken
from passbook.audit.models import Event, EventAction from passbook.audit.models import Event
class UserSettingsView(LoginRequiredMixin, TemplateView): class UserSettingsView(LoginRequiredMixin, TemplateView):
@ -36,6 +36,6 @@ class DisableView(LoginRequiredMixin, View):
messages.success(request, "Successfully disabled Static OTP Tokens") messages.success(request, "Successfully disabled Static OTP Tokens")
# Create event with email notification # Create event with email notification
Event.new( Event.new(
EventAction.CUSTOM, message="User disabled Static OTP Tokens." "static_otp_disable", message="User disabled Static OTP Tokens."
).from_http(request) ).from_http(request)
return redirect("passbook_stages_otp:otp-user-settings") return redirect("passbook_stages_otp:otp-user-settings")

View File

@ -7,7 +7,7 @@ from django.views import View
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django_otp.plugins.otp_totp.models import TOTPDevice from django_otp.plugins.otp_totp.models import TOTPDevice
from passbook.audit.models import Event, EventAction from passbook.audit.models import Event
class UserSettingsView(LoginRequiredMixin, TemplateView): class UserSettingsView(LoginRequiredMixin, TemplateView):
@ -32,7 +32,7 @@ class DisableView(LoginRequiredMixin, View):
totp.delete() totp.delete()
messages.success(request, "Successfully disabled Time-based OTP") messages.success(request, "Successfully disabled Time-based OTP")
# Create event with email notification # Create event with email notification
Event.new( Event.new("totp_disable", message="User disabled Time-based OTP.").from_http(
EventAction.CUSTOM, message="User disabled Time-based OTP." request
).from_http(request) )
return redirect("passbook_stages_otp:otp-user-settings") return redirect("passbook_stages_otp:otp-user-settings")