api: add API for config used in SPA

This commit is contained in:
Jens Langhammer 2020-11-23 11:49:09 +01:00
parent c0fd3e79bc
commit bd9bce4c9b
4 changed files with 73 additions and 20 deletions

39
passbook/api/v2/config.py Normal file
View file

@ -0,0 +1,39 @@
"""core Configs API"""
from drf_yasg2.utils import swagger_auto_schema
from rest_framework.permissions import AllowAny
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.serializers import ReadOnlyField, Serializer
from rest_framework.viewsets import ViewSet
from passbook.lib.config import CONFIG
class ConfigSerializer(Serializer):
"""Serialize passbook Config into DRF Object"""
branding_logo = ReadOnlyField()
branding_title = ReadOnlyField()
def create(self, request: Request) -> Response:
raise NotImplementedError
def update(self, request: Request) -> Response:
raise NotImplementedError
class ConfigsViewSet(ViewSet):
"""Read-only view set that returns the current session's Configs"""
permission_classes = [AllowAny]
@swagger_auto_schema(responses={200: ConfigSerializer(many=True)})
def list(self, request: Request) -> Response:
"""Retrive public configuration options"""
config = ConfigSerializer(
{
"branding_logo": CONFIG.y("passbook.branding.logo"),
"branding_title": CONFIG.y("passbook.branding.title"),
}
)
return Response(config.data)

View file

@ -8,6 +8,7 @@ from rest_framework.permissions import AllowAny
from passbook.admin.api.overview import AdministrationOverviewViewSet
from passbook.admin.api.overview_metrics import AdministrationMetricsViewSet
from passbook.admin.api.tasks import TaskViewSet
from passbook.api.v2.config import ConfigsViewSet
from passbook.api.v2.messages import MessagesViewSet
from passbook.audit.api import EventViewSet
from passbook.core.api.applications import ApplicationViewSet
@ -57,6 +58,7 @@ from passbook.stages.user_write.api import UserWriteStageViewSet
router = routers.DefaultRouter()
router.register("root/messages", MessagesViewSet, basename="messages")
router.register("root/config", ConfigsViewSet, basename="configs")
router.register(
"admin/overview", AdministrationOverviewViewSet, basename="admin_overview"

View file

@ -1,4 +1,5 @@
"""User API Views"""
from drf_yasg2.utils import swagger_auto_schema
from rest_framework.decorators import action
from rest_framework.request import Request
from rest_framework.response import Response
@ -35,6 +36,7 @@ class UserViewSet(ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
@swagger_auto_schema(responses={200: UserSerializer(many=False)})
@action(detail=False)
# pylint: disable=invalid-name
def me(self, request: Request) -> Response:

View file

@ -647,26 +647,8 @@ paths:
type: integer
responses:
'200':
description: ''
description: User Serializer
schema:
required:
- count
- results
type: object
properties:
count:
type: integer
next:
type: string
format: uri
x-nullable: true
previous:
type: string
format: uri
x-nullable: true
results:
type: array
items:
$ref: '#/definitions/User'
tags:
- core
@ -3642,6 +3624,22 @@ paths:
description: A unique integer value identifying this SAML Provider.
required: true
type: integer
/root/config/:
get:
operationId: root_config_list
description: Retrive public configuration options
parameters: []
responses:
'200':
description: Serialize passbook Config into DRF Object
schema:
description: ''
type: array
items:
$ref: '#/definitions/Config'
tags:
- root
parameters: []
/root/messages/:
get:
operationId: root_messages_list
@ -7577,6 +7575,18 @@ definitions:
type: string
format: uuid
x-nullable: true
Config:
description: Serialize passbook Config into DRF Object
type: object
properties:
branding_logo:
title: Branding logo
type: string
readOnly: true
branding_title:
title: Branding title
type: string
readOnly: true
Message:
description: Serialize Django Message into DRF Object
type: object