From 5314485426e172fca5df87ac29617414668143d0 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 14:09:24 +0200 Subject: [PATCH] enterprise/rac: fix error when listing connection tokens as non-superuser (cherry-pick #10771) (#10773) enterprise/rac: fix error when listing connection tokens as non-superuser (#10771) Signed-off-by: Jens Langhammer Co-authored-by: Jens L. --- .../providers/rac/api/connection_tokens.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/authentik/enterprise/providers/rac/api/connection_tokens.py b/authentik/enterprise/providers/rac/api/connection_tokens.py index 3455112cf2c4..3bbf6bcdae01 100644 --- a/authentik/enterprise/providers/rac/api/connection_tokens.py +++ b/authentik/enterprise/providers/rac/api/connection_tokens.py @@ -34,6 +34,12 @@ class Meta: ] +class ConnectionTokenOwnerFilter(OwnerFilter): + """Owner filter for connection tokens (checks session's user)""" + + owner_key = "session__user" + + class ConnectionTokenViewSet( mixins.RetrieveModelMixin, mixins.UpdateModelMixin, @@ -50,4 +56,9 @@ class ConnectionTokenViewSet( search_fields = ["endpoint__name", "provider__name"] ordering = ["endpoint__name", "provider__name"] permission_classes = [OwnerSuperuserPermissions] - filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter] + filter_backends = [ + ConnectionTokenOwnerFilter, + DjangoFilterBackend, + OrderingFilter, + SearchFilter, + ]