From a99818f7cd65bfcd453f88ec0f6a2db7e2d7bf6d Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Tue, 1 Aug 2017 17:25:55 -0700 Subject: [PATCH] checking project and inventory "use" permission to remediate --- .../src/inventories-hosts/inventories/main.js | 58 ++++++++++++------- .../edit/inventory-edit.controller.js | 3 +- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/awx/ui/client/src/inventories-hosts/inventories/main.js b/awx/ui/client/src/inventories-hosts/inventories/main.js index 184d46e195..9587e32086 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/main.js +++ b/awx/ui/client/src/inventories-hosts/inventories/main.js @@ -123,35 +123,51 @@ angular.module('inventory', [ 'status: ' + status }); }); - }], - CanRemediate: ['resourceData', '$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', - function(resourceData, $stateParams, Rest, GetBasePath, ProcessErrors){ + }], + checkProjectPermission: ['resourceData', '$stateParams', 'Rest', 'GetBasePath', + function(resourceData, $stateParams, Rest, GetBasePath){ if(_.has(resourceData, 'data.summary_fields.insights_credential')){ let credential_id = resourceData.data.summary_fields.insights_credential.id, - path = `${GetBasePath('projects')}?credential__id=${credential_id}&role_level=use_role`; - Rest.setUrl(path); - return Rest.get() - .then(({data}) => { - if (data.results.length > 0){ - return true; - } - else { + path = `${GetBasePath('projects')}?credential__id=${credential_id}&role_level=use_role`; + Rest.setUrl(path); + return Rest.get().then(({data}) => { + if (data.results.length > 0){ + return true; + } + else { + return false; + } + }).catch(() => { return false; - } - }) - .catch(({data, status}) => { - ProcessErrors(null, data, status, null, { - hdr: 'Error!', - msg: 'Failed to get instance groups. GET returned ' + - 'status: ' + status }); - }); } else { return false; } - - }] + }], + checkInventoryPermission: ['resourceData', '$stateParams', 'Rest', 'GetBasePath', + function(resourceData, $stateParams, Rest, GetBasePath){ + if(_.has(resourceData, 'data.summary_fields.insights_credential')){ + let path = `${GetBasePath('inventory')}${$stateParams.inventory_id}/?role_level=use_role`; + Rest.setUrl(path); + return Rest.get().then(() => { + return true; + }).catch(() => { + return false; + }); + } + else { + return false; + } + }], + CanRemediate: ['checkProjectPermission', 'checkInventoryPermission', + function(checkProjectPermission, checkInventoryPermission){ + // the user can remediate an insights + // inv if the user has "use" permission on + // an insights project and the inventory + // being edited: + return checkProjectPermission === true && checkInventoryPermission === true; + }] }, } diff --git a/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/edit/inventory-edit.controller.js b/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/edit/inventory-edit.controller.js index 0c003841ed..58a428304a 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/edit/inventory-edit.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/edit/inventory-edit.controller.js @@ -117,5 +117,6 @@ export default ['$scope', '$location', '$stateParams', 'InventoryForm', 'Rest', 'ProcessErrors', 'GetBasePath', 'ParseTypeChange', 'Wait', 'ToJSON', 'ParseVariableString', - '$state', 'OrgAdminLookup', '$rootScope', 'resourceData', 'CreateSelect2', 'InstanceGroupsService', 'InstanceGroupsData', InventoriesEdit, + '$state', 'OrgAdminLookup', '$rootScope', 'resourceData', 'CreateSelect2', + 'InstanceGroupsService', 'InstanceGroupsData', 'CanRemediate', InventoriesEdit, ];