switch to drf_yasg
This commit is contained in:
parent
458decfbb3
commit
d3d75737ed
6
passbook/admin/api/urls.py
Normal file
6
passbook/admin/api/urls.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
"""Versioned Admin API Urls"""
|
||||
from django.conf.urls import include, url
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^v1/', include('passbook.admin.api.v1.urls', namespace='v1')),
|
||||
]
|
22
passbook/admin/api/v1/applications.py
Normal file
22
passbook/admin/api/v1/applications.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
"""passbook admin application API"""
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from passbook.core.models import Application
|
||||
|
||||
|
||||
class ApplicationSerializer(ModelSerializer):
|
||||
"""Application Serializer"""
|
||||
|
||||
class Meta:
|
||||
model = Application
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ApplicationViewSet(ModelViewSet):
|
||||
"""Application Viewset"""
|
||||
|
||||
permission_classes = [IsAdminUser]
|
||||
serializer_class = ApplicationSerializer
|
||||
queryset = Application.objects.all()
|
|
@ -1,9 +1,33 @@
|
|||
"""passbook admin API URLs"""
|
||||
from django.urls import path
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.views import get_schema_view
|
||||
from rest_framework import permissions
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from passbook.admin.api.v1.applications import ApplicationViewSet
|
||||
from passbook.admin.api.v1.groups import GroupViewSet
|
||||
from passbook.admin.api.v1.users import UserViewSet
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register(r'groups', GroupViewSet)
|
||||
router.register('applications', ApplicationViewSet)
|
||||
router.register('groups', GroupViewSet)
|
||||
router.register('users', UserViewSet)
|
||||
|
||||
urlpatterns = router.urls
|
||||
SchemaView = get_schema_view(
|
||||
openapi.Info(
|
||||
title="passbook Administration API",
|
||||
default_version='v1',
|
||||
description="Internal passbook API for Administration Interface",
|
||||
contact=openapi.Contact(email="contact@snippets.local"),
|
||||
license=openapi.License(name="MIT License"),
|
||||
),
|
||||
public=True,
|
||||
permission_classes=(permissions.IsAdminUser,),
|
||||
)
|
||||
|
||||
urlpatterns = router.urls + [
|
||||
path('swagger.yml', SchemaView.without_ui(cache_timeout=0), name='schema-json'),
|
||||
path('swagger/', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||
]
|
||||
app_name = 'passbook.admin'
|
||||
|
|
23
passbook/admin/api/v1/users.py
Normal file
23
passbook/admin/api/v1/users.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
"""passbook admin user API"""
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
|
||||
from passbook.core.models import User
|
||||
|
||||
|
||||
class UserSerializer(ModelSerializer):
|
||||
"""User Serializer"""
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['is_superuser', 'username', 'first_name', 'last_name', 'email', 'date_joined',
|
||||
'uuid']
|
||||
|
||||
|
||||
class UserViewSet(ModelViewSet):
|
||||
"""User Viewset"""
|
||||
|
||||
permission_classes = [IsAdminUser]
|
||||
serializer_class = UserSerializer
|
||||
queryset = User.objects.all()
|
|
@ -1,2 +1,2 @@
|
|||
django-rest-framework
|
||||
django-rest-swagger
|
||||
drf_yasg
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
"""passbook URL Configuration"""
|
||||
from django.urls import include, path
|
||||
from rest_framework_swagger.views import get_swagger_view
|
||||
|
||||
from passbook.admin.views import (applications, audit, factors, groups,
|
||||
invitations, overview, policy, providers,
|
||||
sources, users)
|
||||
|
||||
schema_view = get_swagger_view(title='passbook Admin Internal API')
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('', overview.AdministrationOverviewView.as_view(), name='overview'),
|
||||
# Applications
|
||||
|
@ -65,6 +61,5 @@ urlpatterns = [
|
|||
# Groups
|
||||
path('groups/', groups.GroupListView.as_view(), name='groups'),
|
||||
# API
|
||||
path('api/', schema_view),
|
||||
path('api/v1/', include('passbook.admin.api.v1.urls'))
|
||||
path('api/', include('passbook.admin.api.urls'))
|
||||
]
|
||||
|
|
Reference in a new issue