core(major): add api for most simple objects
This commit is contained in:
parent
ffca957838
commit
463c130351
|
@ -2,7 +2,9 @@
|
|||
from django.urls import include, path
|
||||
|
||||
from passbook.api.v1.urls import urlpatterns as v1_urls
|
||||
from passbook.api.v2.urls import urlpatterns as v2_urls
|
||||
|
||||
urlpatterns = [
|
||||
path('v1/', include(v1_urls))
|
||||
path('v1/', include(v1_urls)),
|
||||
path('v2/', include(v2_urls)),
|
||||
]
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
from rest_framework import routers
|
||||
|
||||
from passbook.core.api.applications import ApplicationViewSet
|
||||
from passbook.core.api.groups import GroupViewSet
|
||||
from passbook.core.api.invitations import InvitationViewSet
|
||||
from passbook.core.api.users import UserViewSet
|
||||
from passbook.audit.api.events import EventViewSet
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register('core/applications', ApplicationViewSet)
|
||||
router.register('core/invitations', InvitationViewSet)
|
||||
router.register('core/groups', GroupViewSet)
|
||||
router.register('core/users', UserViewSet)
|
||||
router.register('audit/events', EventViewSet)
|
||||
# router.register('accounts', AccountViewSet)
|
||||
urlpatterns = router.urls
|
|
@ -0,0 +1,18 @@
|
|||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||
|
||||
from passbook.audit.models import Event
|
||||
|
||||
|
||||
class EventSerializer(ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Event
|
||||
fields = ['pk', 'user', 'action', 'date', 'app', 'context', 'request_ip', 'created', ]
|
||||
|
||||
|
||||
class EventViewSet(ReadOnlyModelViewSet):
|
||||
|
||||
queryset = Event.objects.all()
|
||||
serializer_class = EventSerializer
|
|
@ -0,0 +1,19 @@
|
|||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from passbook.core.models import Application
|
||||
|
||||
|
||||
class ApplicationSerializer(ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Application
|
||||
fields = ['pk', 'name', 'slug', 'launch_url', 'icon_url',
|
||||
'provider', 'policies', 'skip_authorization']
|
||||
|
||||
|
||||
class ApplicationViewSet(ModelViewSet):
|
||||
|
||||
queryset = Application.objects.all()
|
||||
serializer_class = ApplicationSerializer
|
|
@ -0,0 +1,18 @@
|
|||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from passbook.core.models import Group
|
||||
|
||||
|
||||
class GroupSerializer(ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Group
|
||||
fields = ['pk', 'name', 'parent', 'user_set', 'attributes']
|
||||
|
||||
|
||||
class GroupViewSet(ModelViewSet):
|
||||
|
||||
queryset = Group.objects.all()
|
||||
serializer_class = GroupSerializer
|
|
@ -0,0 +1,18 @@
|
|||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from passbook.core.models import Invitation
|
||||
|
||||
|
||||
class InvitationSerializer(ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Invitation
|
||||
fields = ['pk', 'expires', 'fixed_username', 'fixed_email', 'needs_confirmation']
|
||||
|
||||
|
||||
class InvitationViewSet(ModelViewSet):
|
||||
|
||||
queryset = Invitation.objects.all()
|
||||
serializer_class = InvitationSerializer
|
|
@ -0,0 +1,18 @@
|
|||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from passbook.core.models import User
|
||||
|
||||
|
||||
class UserSerializer(ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
||||
model = User
|
||||
fields = ['pk', 'username', 'name', 'email']
|
||||
|
||||
|
||||
class UserViewSet(ModelViewSet):
|
||||
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
Reference in New Issue