admin: make tasks's retry api not ask for a body

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-16 18:43:33 +02:00
parent d38fd603dd
commit d0f1daf025
5 changed files with 13 additions and 45 deletions

View File

@ -4,6 +4,7 @@ from importlib import import_module
from django.contrib import messages from django.contrib import messages
from django.http.response import Http404 from django.http.response import Http404
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiResponse, extend_schema from drf_spectacular.utils import OpenApiResponse, extend_schema
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import CharField, ChoiceField, DateTimeField, ListField from rest_framework.fields import CharField, ChoiceField, DateTimeField, ListField
@ -57,11 +58,12 @@ class TaskViewSet(ViewSet):
return Response(TaskSerializer(tasks, many=True).data) return Response(TaskSerializer(tasks, many=True).data)
@extend_schema( @extend_schema(
request=OpenApiTypes.NONE,
responses={ responses={
204: OpenApiResponse(description="Task retried successfully"), 204: OpenApiResponse(description="Task retried successfully"),
404: OpenApiResponse(description="Task not found"), 404: OpenApiResponse(description="Task not found"),
500: OpenApiResponse(description="Failed to retry task"), 500: OpenApiResponse(description="Failed to retry task"),
} },
) )
@action(detail=True, methods=["post"]) @action(detail=True, methods=["post"])
# pylint: disable=invalid-name # pylint: disable=invalid-name

View File

@ -1,9 +1,9 @@
"""authentik administration overview""" """authentik administration overview"""
from drf_spectacular.utils import extend_schema, inline_serializer from drf_spectacular.utils import extend_schema, inline_serializer
from rest_framework.fields import IntegerField
from rest_framework.permissions import IsAdminUser from rest_framework.permissions import IsAdminUser
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.fields import IntegerField
from rest_framework.views import APIView from rest_framework.views import APIView
from authentik.root.celery import CELERY_APP from authentik.root.celery import CELERY_APP
@ -15,12 +15,8 @@ class WorkerView(APIView):
permission_classes = [IsAdminUser] permission_classes = [IsAdminUser]
@extend_schema( @extend_schema(
responses=inline_serializer("Workers", fields={ responses=inline_serializer("Workers", fields={"count": IntegerField()})
"count": IntegerField()
})
) )
def get(self, request: Request) -> Response: def get(self, request: Request) -> Response:
"""Get currently connected worker count.""" """Get currently connected worker count."""
return Response( return Response({"count": len(CELERY_APP.control.ping(timeout=0.5))})
{"count": len(CELERY_APP.control.ping(timeout=0.5))}
)

View File

@ -194,7 +194,11 @@ urlpatterns = (
] ]
+ router.urls + router.urls
+ [ + [
path("admin/metrics/", AdministrationMetricsViewSet.as_view(), name="admin_metrics"), path(
"admin/metrics/",
AdministrationMetricsViewSet.as_view(),
name="admin_metrics",
),
path("admin/version/", VersionView.as_view(), name="admin_version"), path("admin/version/", VersionView.as_view(), name="admin_version"),
path("admin/workers/", WorkerView.as_view(), name="admin_workers"), path("admin/workers/", WorkerView.as_view(), name="admin_workers"),
path("root/config/", ConfigView.as_view(), name="config"), path("root/config/", ConfigView.as_view(), name="config"),

View File

@ -97,18 +97,6 @@ paths:
required: true required: true
tags: tags:
- admin - admin
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/TaskRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/TaskRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/TaskRequest'
required: true
security: security:
- authentik: [] - authentik: []
- cookieAuth: [] - cookieAuth: []
@ -21666,28 +21654,6 @@ components:
- task_description - task_description
- task_finish_timestamp - task_finish_timestamp
- task_name - task_name
TaskRequest:
type: object
description: Serialize TaskInfo and TaskResult
properties:
task_name:
type: string
task_description:
type: string
task_finish_timestamp:
type: string
format: date-time
status:
$ref: '#/components/schemas/StatusEnum'
messages:
type: array
items: {}
required:
- messages
- status
- task_description
- task_finish_timestamp
- task_name
Token: Token:
type: object type: object
description: Token Serializer description: Token Serializer

View File

@ -105,8 +105,8 @@ export class SystemTaskListPage extends TablePage<Task> {
this.taskStatus(item), this.taskStatus(item),
html`<ak-action-button html`<ak-action-button
.apiRequest=${() => { .apiRequest=${() => {
return new AdminApi(DEFAULT_CONFIG).adminSystemTasksRetry({ return new AdminApi(DEFAULT_CONFIG).adminSystemTasksRetryCreate({
id: item.taskName id: item.taskName,
}); });
}}> }}>
${t`Retry Task`} ${t`Retry Task`}