This commit is contained in:
Langhammer, Jens 2019-10-28 14:44:46 +01:00
parent 463c130351
commit 846a86fb62
7 changed files with 19 additions and 4 deletions

View File

@ -1,10 +1,11 @@
"""api v2 urls"""
from rest_framework import routers from rest_framework import routers
from passbook.audit.api.events import EventViewSet
from passbook.core.api.applications import ApplicationViewSet from passbook.core.api.applications import ApplicationViewSet
from passbook.core.api.groups import GroupViewSet from passbook.core.api.groups import GroupViewSet
from passbook.core.api.invitations import InvitationViewSet from passbook.core.api.invitations import InvitationViewSet
from passbook.core.api.users import UserViewSet from passbook.core.api.users import UserViewSet
from passbook.audit.api.events import EventViewSet
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register('core/applications', ApplicationViewSet) router.register('core/applications', ApplicationViewSet)
@ -12,5 +13,4 @@ router.register('core/invitations', InvitationViewSet)
router.register('core/groups', GroupViewSet) router.register('core/groups', GroupViewSet)
router.register('core/users', UserViewSet) router.register('core/users', UserViewSet)
router.register('audit/events', EventViewSet) router.register('audit/events', EventViewSet)
# router.register('accounts', AccountViewSet)
urlpatterns = router.urls urlpatterns = router.urls

View File

@ -1,3 +1,4 @@
"""Audit API Views"""
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ReadOnlyModelViewSet from rest_framework.viewsets import ReadOnlyModelViewSet
@ -5,6 +6,7 @@ from passbook.audit.models import Event
class EventSerializer(ModelSerializer): class EventSerializer(ModelSerializer):
"""Event Serializer"""
class Meta: class Meta:
@ -13,6 +15,7 @@ class EventSerializer(ModelSerializer):
class EventViewSet(ReadOnlyModelViewSet): class EventViewSet(ReadOnlyModelViewSet):
"""Event Read-Only Viewset"""
queryset = Event.objects.all() queryset = Event.objects.all()
serializer_class = EventSerializer serializer_class = EventSerializer

View File

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

View File

@ -1,3 +1,4 @@
"""Application API Views"""
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
@ -5,6 +6,7 @@ from passbook.core.models import Application
class ApplicationSerializer(ModelSerializer): class ApplicationSerializer(ModelSerializer):
"""Application Serializer"""
class Meta: class Meta:
@ -14,6 +16,7 @@ class ApplicationSerializer(ModelSerializer):
class ApplicationViewSet(ModelViewSet): class ApplicationViewSet(ModelViewSet):
"""Application Viewset"""
queryset = Application.objects.all() queryset = Application.objects.all()
serializer_class = ApplicationSerializer serializer_class = ApplicationSerializer

View File

@ -1,3 +1,4 @@
"""Groups API Viewset"""
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
@ -5,6 +6,7 @@ from passbook.core.models import Group
class GroupSerializer(ModelSerializer): class GroupSerializer(ModelSerializer):
"""Group Serializer"""
class Meta: class Meta:
@ -13,6 +15,7 @@ class GroupSerializer(ModelSerializer):
class GroupViewSet(ModelViewSet): class GroupViewSet(ModelViewSet):
"""Group Viewset"""
queryset = Group.objects.all() queryset = Group.objects.all()
serializer_class = GroupSerializer serializer_class = GroupSerializer

View File

@ -1,3 +1,4 @@
"""Invitation API Views"""
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
@ -5,6 +6,7 @@ from passbook.core.models import Invitation
class InvitationSerializer(ModelSerializer): class InvitationSerializer(ModelSerializer):
"""Invitation Serializer"""
class Meta: class Meta:
@ -13,6 +15,7 @@ class InvitationSerializer(ModelSerializer):
class InvitationViewSet(ModelViewSet): class InvitationViewSet(ModelViewSet):
"""Invitation Viewset"""
queryset = Invitation.objects.all() queryset = Invitation.objects.all()
serializer_class = InvitationSerializer serializer_class = InvitationSerializer

View File

@ -1,3 +1,4 @@
"""User API Views"""
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
@ -5,6 +6,7 @@ from passbook.core.models import User
class UserSerializer(ModelSerializer): class UserSerializer(ModelSerializer):
"""User Serializer"""
class Meta: class Meta:
@ -13,6 +15,7 @@ class UserSerializer(ModelSerializer):
class UserViewSet(ModelViewSet): class UserViewSet(ModelViewSet):
"""User Viewset"""
queryset = User.objects.all() queryset = User.objects.all()
serializer_class = UserSerializer serializer_class = UserSerializer