admin: link to invitation on list

This commit is contained in:
Jens Langhammer 2018-12-10 15:26:28 +01:00
parent d0099edac4
commit 7f2bae4c2c
3 changed files with 10 additions and 4 deletions

View File

@ -26,7 +26,7 @@
{% for invitation in object_list %}
<tr>
<td>{{ invitation.expires|default:"Never" }}</td>
<td><pre>test</pre></td>
<td><pre>{{ invitation.link }}</pre></td>
<td>
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:invitation-delete' pk=invitation.uuid %}?back={{ request.get_full_path }}">{% trans 'Delete' %}</a>
</td>

View File

@ -3,6 +3,7 @@ from json import dumps, loads
from logging import getLogger
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import gettext as _
@ -57,9 +58,12 @@ class AuditEntry(UUIDModel):
def create(action, request, **kwargs):
"""Create AuditEntry from arguments"""
client_ip, _ = get_client_ip(request)
user = request.user
if isinstance(user, AnonymousUser):
user = kwargs.get('user', None)
entry = AuditEntry.objects.create(
action=action,
user=request.user,
user=user,
# User 255.255.255.255 as fallback if IP cannot be determined
request_ip=client_ip or '255.255.255.255',
_context=dumps(kwargs))

View File

@ -26,12 +26,14 @@ def on_user_signed_up(sender, request, user, **kwargs):
@receiver(invitation_created)
def on_invitation_created(sender, request, invitation, **kwargs):
"""Log Invitation creation"""
AuditEntry.create(AuditEntry.ACTION_INVITE_CREATED, request, invitation_uuid=invitation.uuid)
AuditEntry.create(AuditEntry.ACTION_INVITE_CREATED, request,
invitation_uuid=invitation.uuid.hex)
@receiver(invitation_used)
def on_invitation_used(sender, request, invitation, **kwargs):
"""Log Invitation usage"""
AuditEntry.create(AuditEntry.ACTION_INVITE_USED, request, invitation_uuid=invitation.uuid)
AuditEntry.create(AuditEntry.ACTION_INVITE_USED, request,
invitation_uuid=invitation.uuid.hex)
@receiver(user_login_failed)
def on_user_login_failed(sender, request, user, **kwargs):