mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
do not allow tower group delete or name change
* DO allow policy changes and other attribute changes
This commit is contained in:
parent
e58038b056
commit
305ef6fa7e
@ -231,8 +231,10 @@ class IsSuperUser(permissions.BasePermission):
|
||||
|
||||
class InstanceGroupTowerPermission(ModelAccessPermission):
|
||||
def has_object_permission(self, request, view, obj):
|
||||
if request.method not in permissions.SAFE_METHODS:
|
||||
if obj.name == "tower":
|
||||
return False
|
||||
if request.method == 'DELETE' and obj.name == "tower":
|
||||
return False
|
||||
if request.method in ['PATCH', 'PUT'] and obj.name == 'tower' and \
|
||||
request and request.data and request.data.get('name', '') != 'tower':
|
||||
return False
|
||||
return super(InstanceGroupTowerPermission, self).has_object_permission(request, view, obj)
|
||||
|
||||
|
||||
@ -661,6 +661,7 @@ class InstanceGroupList(ListCreateAPIView):
|
||||
|
||||
class InstanceGroupDetail(RelatedJobsPreventDeleteMixin, RetrieveUpdateDestroyAPIView):
|
||||
|
||||
always_allow_superuser = False
|
||||
view_name = _("Instance Group Detail")
|
||||
model = InstanceGroup
|
||||
serializer_class = InstanceGroupSerializer
|
||||
|
||||
@ -466,6 +466,15 @@ class InstanceGroupAccess(BaseAccess):
|
||||
def can_change(self, obj, data):
|
||||
return self.user.is_superuser
|
||||
|
||||
def can_delete(self, obj):
|
||||
return self.user.is_superuser
|
||||
|
||||
def can_attach(self, obj, sub_obj, relationship, *args, **kwargs):
|
||||
return self.user.is_superuser
|
||||
|
||||
def can_unattach(self, obj, sub_obj, relationship, *args, **kwargs):
|
||||
return self.user.is_superuser
|
||||
|
||||
|
||||
class UserAccess(BaseAccess):
|
||||
'''
|
||||
|
||||
@ -80,11 +80,12 @@ def test_delete_instance_group_jobs_running(delete, instance_group_jobs_running,
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_delete_tower_instance_group_prevented(delete, options, tower_instance_group, admin):
|
||||
def test_delete_tower_instance_group_prevented(delete, options, tower_instance_group, user):
|
||||
url = reverse("api:instance_group_detail", kwargs={'pk': tower_instance_group.pk})
|
||||
delete(url, None, admin, expect=403)
|
||||
resp = options(url, None, admin, expect=200)
|
||||
actions = ['DELETE', 'PATCH', 'PUT']
|
||||
super_user = user('bob', True)
|
||||
delete(url, None, super_user, expect=403)
|
||||
resp = options(url, None, super_user, expect=200)
|
||||
actions = ['GET', 'PUT',]
|
||||
assert 'DELETE' not in resp.data['actions']
|
||||
for action in actions:
|
||||
assert action not in resp.data['actions']
|
||||
assert 'GET' in resp.data['actions']
|
||||
assert action in resp.data['actions']
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user