From 37003a52cf62ebfbfc0c9506f9a4b9f21136804b Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 25 Sep 2017 11:35:03 -0400 Subject: [PATCH] Tweaked permissions logic to fix bug which prevented editing a JT without a default inv --- .../job-template-edit.controller.js | 6 +- awx/ui/client/src/templates/main.js | 86 +++++++++++-------- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js b/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js index 2a74692075..fa5d74219a 100644 --- a/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js +++ b/awx/ui/client/src/templates/job_templates/edit-job-template/job-template-edit.controller.js @@ -18,7 +18,7 @@ export default 'Empty', 'Prompt', 'ToJSON', 'GetChoices', 'CallbackHelpInit', 'InitiatePlaybookRun' , 'initSurvey', '$state', 'CreateSelect2', 'ToggleNotification','$q', 'InstanceGroupsService', 'InstanceGroupsData', 'MultiCredentialService', 'availableLabels', - 'canGetProject', 'canGetInventory', 'jobTemplateData', 'ParseVariableString', + 'projectGetPermissionDenied', 'inventoryGetPermissionDenied', 'jobTemplateData', 'ParseVariableString', function( $filter, $scope, $rootScope, $location, $stateParams, JobTemplateForm, GenerateForm, Rest, Alert, @@ -26,7 +26,7 @@ export default ParseTypeChange, Wait, selectedLabels, i18n, Empty, Prompt, ToJSON, GetChoices, CallbackHelpInit, InitiatePlaybookRun, SurveyControllerInit, $state, CreateSelect2, ToggleNotification, $q, InstanceGroupsService, InstanceGroupsData, MultiCredentialService, availableLabels, - canGetProject, canGetInventory, jobTemplateData, ParseVariableString + projectGetPermissionDenied, inventoryGetPermissionDenied, jobTemplateData, ParseVariableString ) { $scope.$watch('job_template_obj.summary_fields.user_capabilities.edit', function(val) { @@ -360,7 +360,7 @@ export default MultiCredentialService.loadCredentials(jobTemplateData) .then(([selectedCredentials, credTypes, credTypeOptions, credTags, credentialGetPermissionDenied]) => { - $scope.canGetAllRelatedResources = canGetProject && canGetInventory && !credentialGetPermissionDenied ? true : false; + $scope.canGetAllRelatedResources = !projectGetPermissionDenied && !inventoryGetPermissionDenied && !credentialGetPermissionDenied ? true : false; $scope.selectedCredentials = selectedCredentials; $scope.credential_types = credTypes; $scope.credentialTypeOptions = credTypeOptions; diff --git a/awx/ui/client/src/templates/main.js b/awx/ui/client/src/templates/main.js index 564309fffe..55ca52f908 100644 --- a/awx/ui/client/src/templates/main.js +++ b/awx/ui/client/src/templates/main.js @@ -150,47 +150,57 @@ angular.module('templates', [surveyMaker.name, templatesList.name, jobTemplates. }); }); }], - canGetProject: ['Rest', 'ProcessErrors', 'jobTemplateData', + projectGetPermissionDenied: ['Rest', 'ProcessErrors', 'jobTemplateData', function(Rest, ProcessErrors, jobTemplateData) { - Rest.setUrl(jobTemplateData.related.project); - return Rest.get() - .then(() => { - return true; - }) - .catch(({data, status}) => { - if (status === 403) { - /* User doesn't have read access to the project, no problem. */ - } else { - ProcessErrors(null, data, status, null, { - hdr: 'Error!', - msg: 'Failed to get project. GET returned ' + - 'status: ' + status - }); - } - - return false; - }); + if(jobTemplateData.related.project) { + Rest.setUrl(jobTemplateData.related.project); + return Rest.get() + .then(() => { + return false; + }) + .catch(({data, status}) => { + if (status !== 403) { + ProcessErrors(null, data, status, null, { + hdr: 'Error!', + msg: 'Failed to get project. GET returned ' + + 'status: ' + status + }); + return false; + } + else { + return true; + } + }); + } + else { + return false; + } }], - canGetInventory: ['Rest', 'ProcessErrors', 'jobTemplateData', + inventoryGetPermissionDenied: ['Rest', 'ProcessErrors', 'jobTemplateData', function(Rest, ProcessErrors, jobTemplateData) { - Rest.setUrl(jobTemplateData.related.inventory); - return Rest.get() - .then(() => { - return true; - }) - .catch(({data, status}) => { - if (status === 403) { - /* User doesn't have read access to the project, no problem. */ - } else { - ProcessErrors(null, data, status, null, { - hdr: 'Error!', - msg: 'Failed to get project. GET returned ' + - 'status: ' + status - }); - } - - return false; - }); + if(jobTemplateData.related.inventory) { + Rest.setUrl(jobTemplateData.related.inventory); + return Rest.get() + .then(() => { + return false; + }) + .catch(({data, status}) => { + if (status !== 403) { + ProcessErrors(null, data, status, null, { + hdr: 'Error!', + msg: 'Failed to get project. GET returned ' + + 'status: ' + status + }); + return false; + } + else { + return true; + } + }); + } + else { + return false; + } }], InstanceGroupsData: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', function($stateParams, Rest, GetBasePath, ProcessErrors){