From 49bf82a0a49d7e80b596efebf9eaad9620fc6a84 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 6 May 2021 13:44:42 +0200 Subject: [PATCH] core: add user filter by superuser status Signed-off-by: Jens Langhammer --- authentik/core/api/users.py | 9 +++++++-- authentik/events/api/event.py | 2 +- swagger.yaml | 5 +++++ web/package-lock.json | 11 +++++++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/authentik/core/api/users.py b/authentik/core/api/users.py index 9b0fc38d8..ce17d2afa 100644 --- a/authentik/core/api/users.py +++ b/authentik/core/api/users.py @@ -5,7 +5,7 @@ from django.db.models.query import QuerySet from django.http.response import Http404 from django.urls import reverse_lazy from django.utils.http import urlencode -from django_filters.filters import CharFilter +from django_filters.filters import BooleanFilter, CharFilter from django_filters.filterset import FilterSet from drf_yasg.utils import swagger_auto_schema, swagger_serializer_method from guardian.utils import get_anonymous_user @@ -110,6 +110,11 @@ class UsersFilter(FilterSet): method="filter_attributes", ) + is_superuser = BooleanFilter( + field_name="ak_groups", + lookup_expr="is_superuser" + ) + # pylint: disable=unused-argument def filter_attributes(self, queryset, name, value): """Filter attributes by query args""" @@ -126,7 +131,7 @@ class UsersFilter(FilterSet): class Meta: model = User - fields = ["username", "name", "is_active", "attributes"] + fields = ["username", "name", "is_active", "is_superuser", "attributes"] class UserViewSet(ModelViewSet): diff --git a/authentik/events/api/event.py b/authentik/events/api/event.py index e7234fded..6246f7b1c 100644 --- a/authentik/events/api/event.py +++ b/authentik/events/api/event.py @@ -8,7 +8,7 @@ from rest_framework.decorators import action from rest_framework.fields import CharField, DictField, IntegerField from rest_framework.request import Request from rest_framework.response import Response -from rest_framework.serializers import ModelSerializer, Serializer +from rest_framework.serializers import ModelSerializer from rest_framework.viewsets import ReadOnlyModelViewSet from authentik.core.api.utils import PassiveSerializer, TypeCreateSerializer diff --git a/swagger.yaml b/swagger.yaml index 9a0489983..e20bf0177 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -2021,6 +2021,11 @@ paths: description: '' required: false type: string + - name: is_superuser + in: query + description: '' + required: false + type: string - name: attributes in: query description: '' diff --git a/web/package-lock.json b/web/package-lock.json index 5c504b6a9..b314b2f64 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -61,12 +61,13 @@ "typescript": "^4.2.4", "webcomponent-qr-code": "^1.0.5", "yaml": "^1.10.2" - } + }, + "devDependencies": {} }, "api": { "name": "authentik-api", - "version": "0.0.1", - "dependencies": { + "version": "1.0.0", + "devDependencies": { "typescript": "^3.6" } }, @@ -74,6 +75,7 @@ "version": "3.9.9", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.9.tgz", "integrity": "sha512-kdMjTiekY+z/ubJCATUPlRDl39vXYiMV9iyeMuEuXZh2we6zz80uovNN2WlAxmmdE/Z/YQe+EbOEXB5RHEED3w==", + "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -10683,7 +10685,8 @@ "typescript": { "version": "3.9.9", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.9.tgz", - "integrity": "sha512-kdMjTiekY+z/ubJCATUPlRDl39vXYiMV9iyeMuEuXZh2we6zz80uovNN2WlAxmmdE/Z/YQe+EbOEXB5RHEED3w==" + "integrity": "sha512-kdMjTiekY+z/ubJCATUPlRDl39vXYiMV9iyeMuEuXZh2we6zz80uovNN2WlAxmmdE/Z/YQe+EbOEXB5RHEED3w==", + "dev": true } } },