diff --git a/awx/ui/client/src/access/permissions-list.controller.js b/awx/ui/client/src/access/permissions-list.controller.js index 92ed68de9c..f36ee5fa64 100644 --- a/awx/ui/client/src/access/permissions-list.controller.js +++ b/awx/ui/client/src/access/permissions-list.controller.js @@ -20,7 +20,7 @@ export default ['$scope', 'ListDefinition', 'Dataset', 'Wait', 'Rest', 'ProcessE $('#prompt-modal').modal('hide'); Wait('start'); Rest.setUrl(url); - Rest.post({ "disassociate": true, "id": userId }) + Rest.post({ "disassociate": true, "id": Number(userId) }) .success(function() { Wait('stop'); $state.go('.', null, {reload: true}); diff --git a/awx/ui/client/src/inventories-hosts/inventories/insights/insights.controller.js b/awx/ui/client/src/inventories-hosts/inventories/insights/insights.controller.js index 0e143d0b35..5022fc519d 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/insights/insights.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/insights/insights.controller.js @@ -5,8 +5,9 @@ *************************************************/ export default [ 'InsightsData', '$scope', 'moment', '$state', 'InventoryData', - 'InsightsService', -function (data, $scope, moment, $state, InventoryData, InsightsService) { + 'InsightsService', 'CanRemediate', +function (data, $scope, moment, $state, InventoryData, InsightsService, + CanRemediate) { function init() { $scope.reports = (data && data.reports) ? data.reports : []; @@ -24,7 +25,7 @@ function (data, $scope, moment, $state, InventoryData, InsightsService) { $scope.insights_credential = (InventoryData && InventoryData.summary_fields && InventoryData.summary_fields.insights_credential && InventoryData.summary_fields.insights_credential.id) ? InventoryData.summary_fields.insights_credential.id : null; - + $scope.canRemediate = CanRemediate; } function filter(str){ diff --git a/awx/ui/client/src/inventories-hosts/inventories/insights/insights.partial.html b/awx/ui/client/src/inventories-hosts/inventories/insights/insights.partial.html index 5bd39fb816..986decd7b2 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/insights/insights.partial.html +++ b/awx/ui/client/src/inventories-hosts/inventories/insights/insights.partial.html @@ -61,7 +61,7 @@
- No data is available. Either there are no issues to report or no scan jobs have been run on this host. + No data is available. There are no issues to report.
The Insights Credential for {{inventory.name}} was not found. @@ -88,6 +88,6 @@
- +
diff --git a/awx/ui/client/src/inventories-hosts/inventories/insights/insights.route.js b/awx/ui/client/src/inventories-hosts/inventories/insights/insights.route.js index 179af657af..cd116fa062 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/insights/insights.route.js +++ b/awx/ui/client/src/inventories-hosts/inventories/insights/insights.route.js @@ -49,6 +49,50 @@ export default { return resourceData.data; } } - ] + ], + checkProjectPermission: ['InventoryData', '$stateParams', 'Rest', 'GetBasePath', + function(InventoryData, $stateParams, Rest, GetBasePath){ + if(_.has(InventoryData, 'summary_fields.insights_credential')){ + let credential_id = InventoryData.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 { + return false; + } + }).catch(() => { + return false; + }); + } + else { + return false; + } + }], + checkInventoryPermission: ['InventoryData', '$stateParams', 'Rest', 'GetBasePath', + function(InventoryData, $stateParams, Rest, GetBasePath){ + if(_.has(InventoryData, 'summary_fields.insights_credential')){ + let path = `${GetBasePath('inventory')}${InventoryData.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/main.js b/awx/ui/client/src/inventories-hosts/inventories/main.js index 22c8c773e5..9587e32086 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/main.js +++ b/awx/ui/client/src/inventories-hosts/inventories/main.js @@ -123,8 +123,53 @@ angular.module('inventory', [ 'status: ' + status }); }); - }] - } + }], + 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 { + return false; + } + }).catch(() => { + return false; + }); + } + 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 2af0a612b0..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 @@ -13,7 +13,8 @@ function InventoriesEdit($scope, $location, $stateParams, InventoryForm, Rest, ProcessErrors, GetBasePath, ParseTypeChange, Wait, ToJSON, - ParseVariableString, $state, OrgAdminLookup, $rootScope, resourceData, CreateSelect2, InstanceGroupsService, InstanceGroupsData) { + ParseVariableString, $state, OrgAdminLookup, $rootScope, resourceData, + CreateSelect2, InstanceGroupsService, InstanceGroupsData, CanRemediate) { // Inject dynamic view let defaultUrl = GetBasePath('inventory'), @@ -37,6 +38,7 @@ function InventoriesEdit($scope, $location, $scope.inventory_variables = inventoryData.variables === null || inventoryData.variables === '' ? '---' : ParseVariableString(inventoryData.variables); $scope.parseType = 'yaml'; $scope.instance_groups = InstanceGroupsData; + $scope.canRemediate = CanRemediate; $rootScope.$on('$stateChangeSuccess', function(event, toState) { if(toState.name === 'inventories.edit') { @@ -115,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, ]; diff --git a/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/inventory.form.js b/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/inventory.form.js index 6a720ceb31..fa4ed8d106 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/inventory.form.js +++ b/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/inventory.form.js @@ -201,7 +201,7 @@ function(i18n, InventoryCompletedJobsList) { relatedButtons: { remediate_inventory: { ngClick: 'remediateInventory(id, insights_credential)', - ngShow: 'is_insights && mode !== "add"', + ngShow: 'is_insights && mode !== "add" && canRemediate', label: i18n._('Remediate Inventory'), class: 'Form-primaryButton' }