mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
Don't allow deleting yourself or the very last superuser.
This commit is contained in:
parent
ca949eb71e
commit
36e8dcff7c
@ -144,6 +144,13 @@ class UserAccess(BaseAccess):
|
||||
return bool(obj.organizations.filter(admins__in=[self.user]).count())
|
||||
|
||||
def can_delete(self, obj):
|
||||
if obj == self.user:
|
||||
# cannot delete yourself
|
||||
return False
|
||||
super_users = User.objects.filter(is_superuser=True)
|
||||
if obj.is_superuser and super_users.count() == 1:
|
||||
# cannot delete the last superuser
|
||||
return False
|
||||
return bool(self.user.is_superuser or
|
||||
obj.organizations.filter(admins__in=[self.user]).count())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user