astrosat / django-astrosat-users

Common backend library for Astrosat projects' user management
GNU General Public License v3.0
2 stars 0 forks source link

move api_schema view into django-astrosat-core #15

Closed allynt closed 4 years ago

allynt commented 4 years ago

this code should be moved out of django-astrosat-users and into django-astrosat-core:

from django.conf import settings
from django.urls import re_path

from rest_framework.permissions import BasePermission

from drf_yasg.views import get_schema_view
from drf_yasg import openapi

class IsAdminOrDebug(BasePermission):

    def has_object_permission(self, request, view, obj):
        user = request.user
        return user.is_superuser or settings.DEBUG

api_schema_view = get_schema_view(
    openapi.Info(title=f"{settings.PROJECT_NAME} API", default_version="v1"),
    public=True,
    permission_classes=(IsAdminOrDebug,)
)

api_schema_views = [
    re_path(
        r"^swagger(?P<format>\.json|\.yaml)$",
        api_schema_view.without_ui(cache_timeout=0),
        name="swagger-json",
    ),
    re_path(
        r"^swagger/$",
        api_schema_view.with_ui("swagger", cache_timeout=0),
        name="swagger",
    ),
    re_path(
        r"^redoc/$",
        api_schema_view.with_ui("redoc", cache_timeout=0),
        name="swagger-redoc",
    ),
]
allynt commented 4 years ago

Done.