diff --git a/passbook/api/urls.py b/passbook/api/urls.py index fa35789b7..1685de242 100644 --- a/passbook/api/urls.py +++ b/passbook/api/urls.py @@ -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)), ] diff --git a/passbook/api/v2/urls.py b/passbook/api/v2/urls.py new file mode 100644 index 000000000..c0d8a92f4 --- /dev/null +++ b/passbook/api/v2/urls.py @@ -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 diff --git a/passbook/audit/api/__init__.py b/passbook/audit/api/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/audit/api/events.py b/passbook/audit/api/events.py new file mode 100644 index 000000000..4555c9793 --- /dev/null +++ b/passbook/audit/api/events.py @@ -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 diff --git a/passbook/core/api/__init__.py b/passbook/core/api/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/core/api/applications.py b/passbook/core/api/applications.py new file mode 100644 index 000000000..8be2731f8 --- /dev/null +++ b/passbook/core/api/applications.py @@ -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 diff --git a/passbook/core/api/groups.py b/passbook/core/api/groups.py new file mode 100644 index 000000000..02a11014e --- /dev/null +++ b/passbook/core/api/groups.py @@ -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 diff --git a/passbook/core/api/invitations.py b/passbook/core/api/invitations.py new file mode 100644 index 000000000..03bd0926d --- /dev/null +++ b/passbook/core/api/invitations.py @@ -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 diff --git a/passbook/core/api/users.py b/passbook/core/api/users.py new file mode 100644 index 000000000..b937db88e --- /dev/null +++ b/passbook/core/api/users.py @@ -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