Skip to content
Snippets Groups Projects
Commit a37baaad authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'stale-read-delete-admin' into 'master'

Prevent removing all admins of a group using the default DB

Closes #644

See merge request !1207
parents 2e0b31de 051d8f3c
No related branches found
No related tags found
1 merge request!1207Prevent removing all admins of a group using the default DB
......@@ -641,11 +641,11 @@ class MembershipDetails(RetrieveUpdateDestroyAPIView):
)
def perform_destroy(self, instance):
# At list one admin member must exist except for workers which depends on their repositories
# At least one admin member must exist except for workers which depends on their repositories
if (
instance.content_type != ContentType.objects.get_for_model(Worker)
and instance.level >= Role.Admin.value
and instance.content_object.memberships.filter(level__gte=Role.Admin.value).count() < 2
and instance.content_object.memberships.using('default').filter(level__gte=Role.Admin.value).count() < 2
):
raise ValidationError({'detail': ['Removing all memberships with an admin privilege is not possible.']})
return super().perform_destroy(instance)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment