*: use Audit custom event action, add SOURCE_LINKED event action
This commit is contained in:
parent
dbcdab05ff
commit
945d5bfaf6
|
@ -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"),
|
||||
]
|
||||
),
|
||||
),
|
||||
]
|
|
@ -104,6 +104,8 @@ class EventAction(models.TextChoices):
|
|||
INVITE_CREATED = "invitation_created"
|
||||
INVITE_USED = "invitation_used"
|
||||
|
||||
SOURCE_LINKED = "source_linked"
|
||||
|
||||
IMPERSONATION_STARTED = "impersonation_started"
|
||||
IMPERSONATION_ENDED = "impersonation_ended"
|
||||
|
||||
|
|
|
@ -57,9 +57,7 @@ def on_user_logged_out(sender, request: HttpRequest, user: User, **_):
|
|||
# pylint: disable=unused-argument
|
||||
def on_user_write(sender, request: HttpRequest, user: User, data: Dict[str, Any], **_):
|
||||
"""Log User write"""
|
||||
thread = EventNewThread(
|
||||
EventAction.CUSTOM, request, caller="stages/user_write", **data
|
||||
)
|
||||
thread = EventNewThread("stages/user_write", request, **data)
|
||||
thread.user = user
|
||||
thread.run()
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||
from django.test import TestCase
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -182,7 +182,7 @@ class OAuthCallback(OAuthClientMixin, View):
|
|||
access.save()
|
||||
UserOAuthSourceConnection.objects.filter(pk=access.pk).update(user=user)
|
||||
Event.new(
|
||||
EventAction.CUSTOM, message="Linked OAuth Source", source=source
|
||||
EventAction.SOURCE_LINKED, message="Linked OAuth Source", source=source
|
||||
).from_http(self.request)
|
||||
messages.success(
|
||||
self.request,
|
||||
|
|
|
@ -23,6 +23,8 @@ class PostUserEnrollmentStage(StageView):
|
|||
access.save()
|
||||
UserOAuthSourceConnection.objects.filter(pk=access.pk).update(user=user)
|
||||
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)
|
||||
return self.executor.stage_ok()
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.views import View
|
|||
from django.views.generic import TemplateView
|
||||
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):
|
||||
|
@ -36,6 +36,6 @@ class DisableView(LoginRequiredMixin, View):
|
|||
messages.success(request, "Successfully disabled Static OTP Tokens")
|
||||
# Create event with email notification
|
||||
Event.new(
|
||||
EventAction.CUSTOM, message="User disabled Static OTP Tokens."
|
||||
"static_otp_disable", message="User disabled Static OTP Tokens."
|
||||
).from_http(request)
|
||||
return redirect("passbook_stages_otp:otp-user-settings")
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.views import View
|
|||
from django.views.generic import TemplateView
|
||||
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):
|
||||
|
@ -32,7 +32,7 @@ class DisableView(LoginRequiredMixin, View):
|
|||
totp.delete()
|
||||
messages.success(request, "Successfully disabled Time-based OTP")
|
||||
# Create event with email notification
|
||||
Event.new(
|
||||
EventAction.CUSTOM, message="User disabled Time-based OTP."
|
||||
).from_http(request)
|
||||
Event.new("totp_disable", message="User disabled Time-based OTP.").from_http(
|
||||
request
|
||||
)
|
||||
return redirect("passbook_stages_otp:otp-user-settings")
|
||||
|
|
Reference in New Issue