From 79eec5a3a07efcdfbda3b95f66921ff23bccc184 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 5 Oct 2021 13:10:44 +0200 Subject: [PATCH] core: include group uuids in self serializer Signed-off-by: Jens Langhammer --- authentik/core/api/users.py | 15 +++++++++++++-- schema.yml | 14 +++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/authentik/core/api/users.py b/authentik/core/api/users.py index e299c9ca4..138054925 100644 --- a/authentik/core/api/users.py +++ b/authentik/core/api/users.py @@ -104,10 +104,21 @@ class UserSelfSerializer(ModelSerializer): groups = SerializerMethodField() uid = CharField(read_only=True) - def get_groups(self, user: User) -> list[str]: + @extend_schema_field( + ListSerializer( + child=inline_serializer( + "UserSelfGroups", + {"name": CharField(read_only=True), "pk": CharField(read_only=True)}, + ) + ) + ) + def get_groups(self, user: User): """Return only the group names a user is member of""" for group in user.ak_groups.all(): - yield group.name + yield { + "name": group.name, + "pk": group.pk, + } class Meta: diff --git a/schema.yml b/schema.yml index 96e80f3b7..fb159574f 100644 --- a/schema.yml +++ b/schema.yml @@ -29209,7 +29209,7 @@ components: groups: type: array items: - type: string + $ref: '#/components/schemas/UserSelfGroups' readOnly: true email: type: string @@ -29231,6 +29231,18 @@ components: - pk - uid - username + UserSelfGroups: + type: object + properties: + name: + type: string + readOnly: true + pk: + type: string + readOnly: true + required: + - name + - pk UserSelfRequest: type: object description: |-