policies: fix error when viewing/clearing cache

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-03 19:57:50 +02:00
parent 25300c1928
commit 55c24de8c7
2 changed files with 3 additions and 7 deletions

View File

@ -1,5 +1,4 @@
"""NotificationTransport API Views""" """NotificationTransport API Views"""
from django.http.response import Http404
from drf_yasg.utils import no_body, swagger_auto_schema from drf_yasg.utils import no_body, swagger_auto_schema
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import CharField, ListField, SerializerMethodField from rest_framework.fields import CharField, ListField, SerializerMethodField
@ -68,10 +67,7 @@ class NotificationTransportViewSet(ModelViewSet):
def test(self, request: Request, pk=None) -> Response: def test(self, request: Request, pk=None) -> Response:
"""Send example notification using selected transport. Requires """Send example notification using selected transport. Requires
Modify permissions.""" Modify permissions."""
transports = self.get_object() transport: NotificationTransport = self.get_object()
if not transports.exists():
raise Http404
transport: NotificationTransport = transports.first()
notification = Notification( notification = Notification(
severity=NotificationSeverity.NOTICE, severity=NotificationSeverity.NOTICE,
body=f"Test Notification from transport {transport.name}", body=f"Test Notification from transport {transport.name}",

View File

@ -109,14 +109,14 @@ class PolicyViewSet(
) )
return Response(TypeCreateSerializer(data, many=True).data) return Response(TypeCreateSerializer(data, many=True).data)
@permission_required("authentik_policies.view_policy_cache") @permission_required(None, ["authentik_policies.view_policy_cache"])
@swagger_auto_schema(responses={200: CacheSerializer(many=False)}) @swagger_auto_schema(responses={200: CacheSerializer(many=False)})
@action(detail=False, pagination_class=None, filter_backends=[]) @action(detail=False, pagination_class=None, filter_backends=[])
def cache_info(self, request: Request) -> Response: def cache_info(self, request: Request) -> Response:
"""Info about cached policies""" """Info about cached policies"""
return Response(data={"count": len(cache.keys("policy_*"))}) return Response(data={"count": len(cache.keys("policy_*"))})
@permission_required("authentik_policies.clear_policy_cache") @permission_required(None, ["authentik_policies.clear_policy_cache"])
@swagger_auto_schema( @swagger_auto_schema(
request_body=no_body, request_body=no_body,
responses={204: "Successfully cleared cache", 400: "Bad request"}, responses={204: "Successfully cleared cache", 400: "Bad request"},