Skip to content

Commit

Permalink
Add better error message for wfjt create 403
Browse files Browse the repository at this point in the history
Update __init__.py
  • Loading branch information
TheRealHaoLiu committed Jun 28, 2024
1 parent 4e0d199 commit c17dc82
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 7 additions & 0 deletions awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3111,6 +3111,13 @@ class WorkflowJobTemplateList(ListCreateAPIView):
serializer_class = serializers.WorkflowJobTemplateSerializer
always_allow_superuser = False

def check_permissions(self, request):
can_access, messages = request.user.can_access_with_errors(self.model, 'add', request.data)
if not can_access:
self.permission_denied(request, message=messages)

super.check_permissions(request)


class WorkflowJobTemplateDetail(RelatedJobsPreventDeleteMixin, RetrieveUpdateDestroyAPIView):
model = models.WorkflowJobTemplate
Expand Down
19 changes: 14 additions & 5 deletions awx/main/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -2092,11 +2092,20 @@ def can_add(self, data):
if not data: # So the browseable API will work
return Organization.accessible_objects(self.user, 'workflow_admin_role').exists()

return bool(
self.check_related('organization', Organization, data, role_field='workflow_admin_role', mandatory=True)
and self.check_related('inventory', Inventory, data, role_field='use_role')
and self.check_related('execution_environment', ExecutionEnvironment, data, role_field='read_role')
)
if not self.check_related('organization', Organization, data, role_field='workflow_admin_role', mandatory=True):
if data.get('organization', None) is None:
self.messages['organization'] = [_('An organization is required to create a workflow job template for normal user')]
return False

if not self.check_related('inventory', Inventory, data, role_field='use_role'):
self.messages['inventory'] = [_('You do not have use_role to the inventory')]
return False

if not self.check_related('execution_environment', ExecutionEnvironment, data, role_field='read_role'):
self.messages['execution_environment'] = [_('You do not have read_role to the execution environment')]
return False

return True

def can_copy(self, obj):
if self.save_messages:
Expand Down

0 comments on commit c17dc82

Please sign in to comment.