diff --git a/.pylintrc b/.pylintrc index 894546021..fe0922625 100644 --- a/.pylintrc +++ b/.pylintrc @@ -5,4 +5,4 @@ load-plugins=pylint_django,pylint.extensions.bad_builtin extension-pkg-whitelist=lxml const-rgx=[a-zA-Z0-9_]{1,40}$ ignored-modules=django-otp -jobs=4 +jobs=12 diff --git a/passbook/api/v2/urls.py b/passbook/api/v2/urls.py index f0150b367..4dc29f438 100644 --- a/passbook/api/v2/urls.py +++ b/passbook/api/v2/urls.py @@ -10,14 +10,14 @@ from passbook.api.permissions import CustomObjectPermissions from passbook.audit.api import EventViewSet from passbook.core.api.applications import ApplicationViewSet from passbook.core.api.groups import GroupViewSet -from passbook.core.api.policies import PolicyViewSet +from passbook.core.api.messages import MessagesViewSet from passbook.core.api.propertymappings import PropertyMappingViewSet from passbook.core.api.providers import ProviderViewSet from passbook.core.api.sources import SourceViewSet from passbook.core.api.users import UserViewSet from passbook.flows.api import FlowStageBindingViewSet, FlowViewSet, StageViewSet from passbook.lib.utils.reflection import get_apps -from passbook.policies.api import PolicyBindingViewSet +from passbook.policies.api import PolicyBindingViewSet, PolicyViewSet from passbook.policies.dummy.api import DummyPolicyViewSet from passbook.policies.expiry.api import PasswordExpiryPolicyViewSet from passbook.policies.expression.api import ExpressionPolicyViewSet @@ -55,6 +55,7 @@ for _passbook_app in get_apps(): router.register("core/applications", ApplicationViewSet) router.register("core/groups", GroupViewSet) router.register("core/users", UserViewSet) +router.register("core/messages", MessagesViewSet, basename="messages") router.register("audit/events", EventViewSet) diff --git a/passbook/core/api/messages.py b/passbook/core/api/messages.py new file mode 100644 index 000000000..0dd68c4a4 --- /dev/null +++ b/passbook/core/api/messages.py @@ -0,0 +1,36 @@ +"""core messages API""" +from django.contrib.messages import get_messages +from drf_yasg.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 + + +class MessageSerializer(Serializer): + """Serialize Django Message into DRF Object""" + + message = ReadOnlyField() + level = ReadOnlyField() + tags = ReadOnlyField() + extra_tags = ReadOnlyField() + level_tag = ReadOnlyField() + + def create(self, request: Request) -> Response: + raise NotImplementedError + + def update(self, request: Request) -> Response: + raise NotImplementedError + + +class MessagesViewSet(ViewSet): + """Read-only view set that returns the current session's messages""" + + permission_classes = [AllowAny] + + @swagger_auto_schema(responses={200: MessageSerializer(many=True)}) + def list(self, request: Request) -> Response: + """List current messages and pass into Serializer""" + all_messages = list(get_messages(request)) + return Response(MessageSerializer(all_messages, many=True).data) diff --git a/passbook/core/api/policies.py b/passbook/core/api/policies.py deleted file mode 100644 index 13d6d7ad9..000000000 --- a/passbook/core/api/policies.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Policy API Views""" -from rest_framework.serializers import ModelSerializer, SerializerMethodField -from rest_framework.viewsets import ReadOnlyModelViewSet - -from passbook.policies.forms import GENERAL_FIELDS -from passbook.policies.models import Policy - - -class PolicySerializer(ModelSerializer): - """Policy Serializer""" - - __type__ = SerializerMethodField(method_name="get_type") - - def get_type(self, obj): - """Get object type so that we know which API Endpoint to use to get the full object""" - return obj._meta.object_name.lower().replace("policy", "") - - class Meta: - - model = Policy - fields = ["pk"] + GENERAL_FIELDS + ["__type__"] - - -class PolicyViewSet(ReadOnlyModelViewSet): - """Policy Viewset""" - - queryset = Policy.objects.all() - serializer_class = PolicySerializer - - def get_queryset(self): - return Policy.objects.select_subclasses() diff --git a/passbook/core/templates/login/base.html b/passbook/core/templates/login/base.html index 6d1070dae..b7234adaa 100644 --- a/passbook/core/templates/login/base.html +++ b/passbook/core/templates/login/base.html @@ -1,96 +1,22 @@ -{% extends 'base/skeleton.html' %} - {% load static %} {% load i18n %} -{% block body %} -