From 9f1e8a1ae22b357f88c480f9e592799f0a2abc33 Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Wed, 9 Jun 2021 10:02:26 -0400 Subject: [PATCH] Allow sysadmins to be able to change the pull field for managed EEs --- awx/api/views/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index a96ac4508e..8d34dcb8a9 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -695,6 +695,7 @@ class TeamAccessList(ResourceAccessList): class ExecutionEnvironmentList(ListCreateAPIView): + always_allow_superuser = False model = models.ExecutionEnvironment serializer_class = serializers.ExecutionEnvironmentSerializer swagger_topic = "Execution Environments" @@ -702,10 +703,22 @@ class ExecutionEnvironmentList(ListCreateAPIView): class ExecutionEnvironmentDetail(RetrieveUpdateDestroyAPIView): + always_allow_superuser = False model = models.ExecutionEnvironment serializer_class = serializers.ExecutionEnvironmentSerializer swagger_topic = "Execution Environments" + def update(self, request, *args, **kwargs): + instance = self.get_object() + fields_to_check = ['name', 'description', 'organization', 'image', 'credential'] + if instance.managed_by_tower and request.user.can_access(models.ExecutionEnvironment, 'change', instance): + for field in fields_to_check: + left = getattr(instance, field, None) + right = request.data.get(field, None) + if left != right: + raise PermissionDenied(_("Only the 'pull' field can be edited for managed execution environments.")) + return super().update(request, *args, **kwargs) + class ExecutionEnvironmentJobTemplateList(SubListAPIView):