mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 03:40:42 -03:30
Don't let Org Admins promote themselves to System Admins
Nor System Auditor
This commit is contained in:
parent
390ac656fa
commit
d79d8cbfba
@ -1248,17 +1248,25 @@ class UserDetail(RetrieveUpdateDestroyAPIView):
|
||||
obj = self.get_object()
|
||||
can_change = request.user.can_access(User, 'change', obj, request.data)
|
||||
can_admin = request.user.can_access(User, 'admin', obj, request.data)
|
||||
|
||||
su_only_edit_fields = ('is_superuser', 'is_system_auditor')
|
||||
admin_only_edit_fields = ('last_name', 'first_name', 'username', 'is_active')
|
||||
|
||||
fields_to_check = ()
|
||||
if not request.user.is_superuser:
|
||||
fields_to_check += su_only_edit_fields
|
||||
|
||||
if can_change and not can_admin:
|
||||
admin_only_edit_fields = ('last_name', 'first_name', 'username',
|
||||
'is_active', 'is_superuser')
|
||||
changed = {}
|
||||
for field in admin_only_edit_fields:
|
||||
left = getattr(obj, field, None)
|
||||
right = request.data.get(field, None)
|
||||
if left is not None and right is not None and left != right:
|
||||
changed[field] = (left, right)
|
||||
if changed:
|
||||
raise PermissionDenied('Cannot change %s.' % ', '.join(changed.keys()))
|
||||
fields_to_check += admin_only_edit_fields
|
||||
|
||||
bad_changes = {}
|
||||
for field in fields_to_check:
|
||||
left = getattr(obj, field, None)
|
||||
right = request.data.get(field, None)
|
||||
if left is not None and right is not None and left != right:
|
||||
bad_changes[field] = (left, right)
|
||||
if bad_changes:
|
||||
raise PermissionDenied('Cannot change %s.' % ', '.join(bad_changes.keys()))
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user