1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Don't allow deleting yourself or the very last superuser.

This commit is contained in:
Michael DeHaan 2013-07-11 17:10:55 -04:00
parent ca949eb71e
commit 36e8dcff7c

View File

@ -144,6 +144,13 @@ class UserAccess(BaseAccess):
return bool(obj.organizations.filter(admins__in=[self.user]).count()) return bool(obj.organizations.filter(admins__in=[self.user]).count())
def can_delete(self, obj): 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 return bool(self.user.is_superuser or
obj.organizations.filter(admins__in=[self.user]).count()) obj.organizations.filter(admins__in=[self.user]).count())