diff --git a/passbook/api/v2/config.py b/passbook/api/v2/config.py new file mode 100644 index 000000000..8f87efe85 --- /dev/null +++ b/passbook/api/v2/config.py @@ -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) diff --git a/passbook/api/v2/urls.py b/passbook/api/v2/urls.py index 39dbe1cb7..0aba5a79b 100644 --- a/passbook/api/v2/urls.py +++ b/passbook/api/v2/urls.py @@ -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" diff --git a/passbook/core/api/users.py b/passbook/core/api/users.py index d410ad1b4..1296e96d2 100644 --- a/passbook/core/api/users.py +++ b/passbook/core/api/users.py @@ -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: diff --git a/swagger.yaml b/swagger.yaml index f431efd5b..22c849247 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -647,27 +647,9 @@ 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' + $ref: '#/definitions/User' tags: - core parameters: [] @@ -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