mirror of
https://github.com/ansible/awx.git
synced 2026-03-22 19:35:02 -02:30
Raise meaningful error when permission denied to copy JT
When a user doesn't have access to all the credentials of a job template, they cannot copy the JT. However, currently we raise a default `PermissionDenied`, which doesn't give the user insight into what's wrong. So, this PR just adds a custom message indicating that access to credentials is missing. Signed-off-by: Vismay Golwala <vgolwala@redhat.com>
This commit is contained in:
@@ -1507,7 +1507,10 @@ class JobTemplateAccess(NotificationAttachMixin, BaseAccess):
|
||||
|
||||
# obj.credentials.all() is accessible ONLY when object is saved (has valid id)
|
||||
credential_manager = getattr(obj, 'credentials', None) if getattr(obj, 'id', False) else Credential.objects.none()
|
||||
return reduce(lambda prev, cred: prev and self.user in cred.use_role, credential_manager.all(), True)
|
||||
user_can_copy = reduce(lambda prev, cred: prev and self.user in cred.use_role, credential_manager.all(), True)
|
||||
if not user_can_copy:
|
||||
raise PermissionDenied(_('Insufficient access to Job Template credentials.'))
|
||||
return user_can_copy
|
||||
|
||||
def can_start(self, obj, validate_license=True):
|
||||
# Check license.
|
||||
|
||||
Reference in New Issue
Block a user