api: add API for config used in SPA
This commit is contained in:
parent
c0fd3e79bc
commit
bd9bce4c9b
39
passbook/api/v2/config.py
Normal file
39
passbook/api/v2/config.py
Normal 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)
|
|
@ -8,6 +8,7 @@ from rest_framework.permissions import AllowAny
|
||||||
from passbook.admin.api.overview import AdministrationOverviewViewSet
|
from passbook.admin.api.overview import AdministrationOverviewViewSet
|
||||||
from passbook.admin.api.overview_metrics import AdministrationMetricsViewSet
|
from passbook.admin.api.overview_metrics import AdministrationMetricsViewSet
|
||||||
from passbook.admin.api.tasks import TaskViewSet
|
from passbook.admin.api.tasks import TaskViewSet
|
||||||
|
from passbook.api.v2.config import ConfigsViewSet
|
||||||
from passbook.api.v2.messages import MessagesViewSet
|
from passbook.api.v2.messages import MessagesViewSet
|
||||||
from passbook.audit.api import EventViewSet
|
from passbook.audit.api import EventViewSet
|
||||||
from passbook.core.api.applications import ApplicationViewSet
|
from passbook.core.api.applications import ApplicationViewSet
|
||||||
|
@ -57,6 +58,7 @@ from passbook.stages.user_write.api import UserWriteStageViewSet
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
|
|
||||||
router.register("root/messages", MessagesViewSet, basename="messages")
|
router.register("root/messages", MessagesViewSet, basename="messages")
|
||||||
|
router.register("root/config", ConfigsViewSet, basename="configs")
|
||||||
|
|
||||||
router.register(
|
router.register(
|
||||||
"admin/overview", AdministrationOverviewViewSet, basename="admin_overview"
|
"admin/overview", AdministrationOverviewViewSet, basename="admin_overview"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""User API Views"""
|
"""User API Views"""
|
||||||
|
from drf_yasg2.utils import swagger_auto_schema
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
@ -35,6 +36,7 @@ class UserViewSet(ModelViewSet):
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
|
|
||||||
|
@swagger_auto_schema(responses={200: UserSerializer(many=False)})
|
||||||
@action(detail=False)
|
@action(detail=False)
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
def me(self, request: Request) -> Response:
|
def me(self, request: Request) -> Response:
|
||||||
|
|
48
swagger.yaml
48
swagger.yaml
|
@ -647,26 +647,8 @@ paths:
|
||||||
type: integer
|
type: integer
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: ''
|
description: User Serializer
|
||||||
schema:
|
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'
|
$ref: '#/definitions/User'
|
||||||
tags:
|
tags:
|
||||||
- core
|
- core
|
||||||
|
@ -3642,6 +3624,22 @@ paths:
|
||||||
description: A unique integer value identifying this SAML Provider.
|
description: A unique integer value identifying this SAML Provider.
|
||||||
required: true
|
required: true
|
||||||
type: integer
|
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/:
|
/root/messages/:
|
||||||
get:
|
get:
|
||||||
operationId: root_messages_list
|
operationId: root_messages_list
|
||||||
|
@ -7577,6 +7575,18 @@ definitions:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
x-nullable: true
|
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:
|
Message:
|
||||||
description: Serialize Django Message into DRF Object
|
description: Serialize Django Message into DRF Object
|
||||||
type: object
|
type: object
|
||||||
|
|
Reference in a new issue