Skip to content

Commit

Permalink
Add better 403 error message for Job template create
Browse files Browse the repository at this point in the history
To create Job template u need access to projects and inventory
  • Loading branch information
TheRealHaoLiu committed Jun 27, 2024
1 parent 6f2307f commit ec2d6a9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions awx/main/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,7 @@ def get_value(Class, field):
inventory = get_value(Inventory, 'inventory')
if inventory:
if self.user not in inventory.use_role:
self.messages['job_template'] = [_('You do not have use permission on Inventory')]
return False

if not self.check_related('execution_environment', ExecutionEnvironment, data, role_field='read_role'):
Expand All @@ -1604,11 +1605,15 @@ def get_value(Class, field):
project = get_value(Project, 'project')
# If the user has admin access to the project (as an org admin), should
# be able to proceed without additional checks.
if project:
return self.user in project.use_role
else:
if not project:
return False

if self.user not in project.use_role:
self.messages['job_template'] = [_('You do not have use permission on Project')]
return False

return True

@check_superuser
def can_copy_related(self, obj):
"""
Expand Down

0 comments on commit ec2d6a9

Please sign in to comment.