From 932c2768295cdde1b784fa0c814132293b2e863b Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Wed, 7 Jan 2015 15:12:49 -0500 Subject: [PATCH] Handle the situation where a Job Template's inventory has been removed and we are trying to determine if a user has the ability to edit or copy it. --- awx/api/serializers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index dfc116495f..2dc2f81a5d 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1348,13 +1348,16 @@ class JobTemplateSerializer(UnifiedJobTemplateSerializer, JobOptionsSerializer): if obj.survey_enabled and ('name' in obj.survey_spec and 'description' in obj.survey_spec): d['survey'] = dict(title=obj.survey_spec['name'], description=obj.survey_spec['description']) request = self.context.get('request', None) - if request is not None and request.user is not None: + if request is not None and request.user is not None and obj.inventory is not None and obj.project is not None: d['can_copy'] = request.user.can_access(JobTemplate, 'add', {'inventory': obj.inventory.pk, 'project': obj.project.pk}) d['can_edit'] = request.user.can_access(JobTemplate, 'change', obj, {'inventory': obj.inventory.pk, 'project': obj.project.pk}) + elif request.user is not None and request.user.is_superuser: + d['can_copy'] = True + d['can_edit'] = True else: d['can_copy'] = False d['can_edit'] = False