core: include group uuids in self serializer
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
cd5e091937
commit
79eec5a3a0
|
@ -104,10 +104,21 @@ class UserSelfSerializer(ModelSerializer):
|
||||||
groups = SerializerMethodField()
|
groups = SerializerMethodField()
|
||||||
uid = CharField(read_only=True)
|
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"""
|
"""Return only the group names a user is member of"""
|
||||||
for group in user.ak_groups.all():
|
for group in user.ak_groups.all():
|
||||||
yield group.name
|
yield {
|
||||||
|
"name": group.name,
|
||||||
|
"pk": group.pk,
|
||||||
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
|
|
14
schema.yml
14
schema.yml
|
@ -29209,7 +29209,7 @@ components:
|
||||||
groups:
|
groups:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: string
|
$ref: '#/components/schemas/UserSelfGroups'
|
||||||
readOnly: true
|
readOnly: true
|
||||||
email:
|
email:
|
||||||
type: string
|
type: string
|
||||||
|
@ -29231,6 +29231,18 @@ components:
|
||||||
- pk
|
- pk
|
||||||
- uid
|
- uid
|
||||||
- username
|
- username
|
||||||
|
UserSelfGroups:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
|
pk:
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
- pk
|
||||||
UserSelfRequest:
|
UserSelfRequest:
|
||||||
type: object
|
type: object
|
||||||
description: |-
|
description: |-
|
||||||
|
|
Reference in a new issue