audit: rewrite to be independent of django http requests, allow custom actions
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
from django.contrib.auth.signals import user_logged_in, user_logged_out
|
||||
from django.dispatch import receiver
|
||||
|
||||
from passbook.audit.models import Event
|
||||
from passbook.audit.models import Event, EventAction
|
||||
from passbook.core.signals import (invitation_created, invitation_used,
|
||||
user_signed_up)
|
||||
|
||||
@ -10,26 +10,24 @@ from passbook.core.signals import (invitation_created, invitation_used,
|
||||
@receiver(user_logged_in)
|
||||
def on_user_logged_in(sender, request, user, **kwargs):
|
||||
"""Log successful login"""
|
||||
Event.create(Event.ACTION_LOGIN, request)
|
||||
Event.new(EventAction.LOGIN).from_http(request)
|
||||
|
||||
@receiver(user_logged_out)
|
||||
def on_user_logged_out(sender, request, user, **kwargs):
|
||||
"""Log successfully logout"""
|
||||
Event.create(Event.ACTION_LOGOUT, request)
|
||||
Event.new(EventAction.LOGOUT).from_http(request)
|
||||
|
||||
@receiver(user_signed_up)
|
||||
def on_user_signed_up(sender, request, user, **kwargs):
|
||||
"""Log successfully signed up"""
|
||||
Event.create(Event.ACTION_SIGN_UP, request)
|
||||
Event.new(EventAction.SIGN_UP).from_http(request)
|
||||
|
||||
@receiver(invitation_created)
|
||||
def on_invitation_created(sender, request, invitation, **kwargs):
|
||||
"""Log Invitation creation"""
|
||||
Event.create(Event.ACTION_INVITE_CREATED, request,
|
||||
invitation_uuid=invitation.uuid.hex)
|
||||
Event.new(EventAction.INVITE_CREATED, invitation_uuid=invitation.uuid.hex).from_http(request)
|
||||
|
||||
@receiver(invitation_used)
|
||||
def on_invitation_used(sender, request, invitation, **kwargs):
|
||||
"""Log Invitation usage"""
|
||||
Event.create(Event.ACTION_INVITE_USED, request,
|
||||
invitation_uuid=invitation.uuid.hex)
|
||||
Event.new(EventAction.INVITE_USED, invitation_uuid=invitation.uuid.hex).from_http(request)
|
||||
|
Reference in New Issue
Block a user