Enable bulk set presence for non-default auth type users

closes #5715
This commit is contained in:
Finn Stutzenstein 2020-11-25 15:06:04 +01:00
parent 03cb8592fe
commit 0a67c24138
No known key found for this signature in database
GPG Key ID: 9042F605C6324654

View File

@ -349,6 +349,8 @@ class UserViewSet(ModelViewSet):
field: 'is_active' | 'is_present' | 'is_committee' field: 'is_active' | 'is_present' | 'is_committee'
value: True|False value: True|False
} }
Is_active and is_committee will not be settable for non-default auth type users.
""" """
ids = request.data.get("user_ids") ids = request.data.get("user_ids")
self.assert_list_of_ints(ids) self.assert_list_of_ints(ids)
@ -361,9 +363,12 @@ class UserViewSet(ModelViewSet):
if not isinstance(value, bool): if not isinstance(value, bool):
raise ValidationError({"detail": "value must be true or false"}) raise ValidationError({"detail": "value must be true or false"})
users = User.objects.filter(auth_type="default").filter(pk__in=ids) users = User.objects.filter(pk__in=ids)
if field != "is_present":
users = users.filter(auth_type="default")
if field == "is_active": if field == "is_active":
users = users.exclude(pk=request.user.id) users = users.exclude(pk=request.user.id)
for user in users: for user in users:
setattr(user, field, value) setattr(user, field, value)
user.save() user.save()