From a603f42cc056dcfdef4ba9f45a05dc4329104605 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 21 May 2021 20:46:59 +0200 Subject: [PATCH] api: add OwnerFilter Signed-off-by: Jens Langhammer --- authentik/api/authorization.py | 11 +++++++++++ swagger.yaml | 1 + web/src/pages/sources/plex/PlexSourceForm.ts | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/authentik/api/authorization.py b/authentik/api/authorization.py index eba573836..765f94637 100644 --- a/authentik/api/authorization.py +++ b/authentik/api/authorization.py @@ -1,9 +1,20 @@ """API Authorization""" from django.db.models import Model +from django.db.models.query import QuerySet +from rest_framework.filters import BaseFilterBackend from rest_framework.permissions import BasePermission from rest_framework.request import Request +class OwnerFilter(BaseFilterBackend): + """Filter objects by their owner""" + + owner_key = "user" + + def filter_queryset(self, request: Request, queryset: QuerySet, view) -> QuerySet: + return queryset.filter(**{self.owner_key: request.user}) + + class OwnerPermissions(BasePermission): """Authorize requests by an object's owner matching the requesting user""" diff --git a/swagger.yaml b/swagger.yaml index b15aa7b98..f631bd9ac 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -18045,6 +18045,7 @@ definitions: required: - name - slug + - plex_token type: object properties: pk: diff --git a/web/src/pages/sources/plex/PlexSourceForm.ts b/web/src/pages/sources/plex/PlexSourceForm.ts index 404f83d44..14f7fbcc9 100644 --- a/web/src/pages/sources/plex/PlexSourceForm.ts +++ b/web/src/pages/sources/plex/PlexSourceForm.ts @@ -46,7 +46,7 @@ export class PlexSourceForm extends ModelForm { } send = (data: PlexSource): Promise => { - data.plexToken = this.plexToken; + data.plexToken = this.plexToken || ""; if (this.instance?.slug) { return new SourcesApi(DEFAULT_CONFIG).sourcesPlexUpdate({ slug: this.instance.slug,