admin: migrate version view to APIView

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-16 18:00:02 +02:00
parent dde1dabf97
commit a7d7b46747
3 changed files with 7 additions and 13 deletions

View File

@ -5,11 +5,10 @@ from django.core.cache import cache
from drf_spectacular.utils import extend_schema
from packaging.version import parse
from rest_framework.fields import SerializerMethodField
from rest_framework.mixins import ListModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from rest_framework.views import APIView
from authentik import ENV_GIT_HASH_KEY, __version__
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
@ -47,17 +46,14 @@ class VersionSerializer(PassiveSerializer):
)
class VersionViewSet(ListModelMixin, GenericViewSet):
class VersionView(APIView):
"""Get running and latest version."""
permission_classes = [IsAuthenticated]
pagination_class = None
filter_backends = []
def get_queryset(self): # pragma: no cover
return None
@extend_schema(responses={200: VersionSerializer(many=False)})
def list(self, request: Request) -> Response:
def get(self, request: Request) -> Response:
"""Get running and latest version."""
return Response(VersionSerializer(True).data)

View File

@ -6,7 +6,7 @@ from rest_framework import routers
from authentik.admin.api.meta import AppsViewSet
from authentik.admin.api.metrics import AdministrationMetricsViewSet
from authentik.admin.api.tasks import TaskViewSet
from authentik.admin.api.version import VersionViewSet
from authentik.admin.api.version import VersionView
from authentik.admin.api.workers import WorkerViewSet
from authentik.api.v2.config import ConfigView
from authentik.api.views import APIBrowserView
@ -98,7 +98,6 @@ from authentik.stages.user_write.api import UserWriteStageViewSet
router = routers.DefaultRouter()
router.register("admin/version", VersionViewSet, basename="admin_version")
router.register("admin/workers", WorkerViewSet, basename="admin_workers")
router.register("admin/system_tasks", TaskViewSet, basename="admin_system_tasks")
router.register("admin/apps", AppsViewSet, basename="apps")
@ -198,6 +197,7 @@ urlpatterns = (
+ router.urls
+ [
path("admin/metrics/", AdministrationMetricsViewSet.as_view(), name="admin_metrics"),
path("admin/version/", VersionView.as_view(), name="admin_version"),
path("root/config/", ConfigView.as_view(), name="config"),
path(
"flows/executor/<slug:flow_slug>/",

View File

@ -121,7 +121,7 @@ paths:
description: Failed to retry task
/api/v2beta/admin/version/:
get:
operationId: admin_version_list
operationId: admin_version_retrieve
description: Get running and latest version.
tags:
- admin
@ -133,9 +133,7 @@ paths:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Version'
$ref: '#/components/schemas/Version'
description: ''
/api/v2beta/admin/workers/:
get: