flows: add API to set background image
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
03ff495011
commit
a09481dea2
|
@ -3,11 +3,12 @@ from dataclasses import dataclass
|
|||
|
||||
from django.core.cache import cache
|
||||
from django.db.models import Model
|
||||
from django.http.response import JsonResponse
|
||||
from django.http.response import HttpResponseBadRequest, JsonResponse
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.utils import no_body, swagger_auto_schema
|
||||
from guardian.shortcuts import get_objects_for_user
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.parsers import MultiPartParser
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import (
|
||||
|
@ -194,3 +195,28 @@ class FlowViewSet(ModelViewSet):
|
|||
)
|
||||
diagram = "\n".join([str(x) for x in header + body + footer])
|
||||
return Response({"diagram": diagram})
|
||||
|
||||
@permission_required("authentik_flows.change_flow")
|
||||
@swagger_auto_schema(
|
||||
request_body=no_body,
|
||||
manual_parameters=[
|
||||
openapi.Parameter(
|
||||
name="file",
|
||||
in_=openapi.IN_FORM,
|
||||
type=openapi.TYPE_FILE,
|
||||
required=True,
|
||||
)
|
||||
],
|
||||
responses={200: "Success"},
|
||||
)
|
||||
@action(detail=True, methods=["POST"], parser_classes=(MultiPartParser,))
|
||||
# pylint: disable=unused-argument
|
||||
def set_background(self, request: Request, slug: str):
|
||||
"""Set Flow background"""
|
||||
app: Flow = self.get_object()
|
||||
icon = request.FILES.get("file", None)
|
||||
if not icon:
|
||||
return HttpResponseBadRequest()
|
||||
app.background = icon
|
||||
app.save()
|
||||
return Response({})
|
||||
|
|
33
swagger.yaml
33
swagger.yaml
|
@ -4062,6 +4062,39 @@ paths:
|
|||
type: string
|
||||
format: slug
|
||||
pattern: ^[-a-zA-Z0-9_]+$
|
||||
/flows/instances/{slug}/set_background/:
|
||||
post:
|
||||
operationId: flows_instances_set_background
|
||||
description: Set Flow background
|
||||
parameters:
|
||||
- name: file
|
||||
in: formData
|
||||
required: true
|
||||
type: file
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
'403':
|
||||
description: Authentication credentials were invalid, absent or insufficient.
|
||||
schema:
|
||||
$ref: '#/definitions/GenericError'
|
||||
'404':
|
||||
description: Object does not exist or caller has insufficient permissions
|
||||
to access it.
|
||||
schema:
|
||||
$ref: '#/definitions/APIException'
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
tags:
|
||||
- flows
|
||||
parameters:
|
||||
- name: slug
|
||||
in: path
|
||||
description: Visible in the URL.
|
||||
required: true
|
||||
type: string
|
||||
format: slug
|
||||
pattern: ^[-a-zA-Z0-9_]+$
|
||||
/oauth2/authorization_codes/:
|
||||
get:
|
||||
operationId: oauth2_authorization_codes_list
|
||||
|
|
Reference in a new issue