- 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 @@
VIEW DATA IN INSIGHTS
- REMEDIATE INVENTORY
+ REMEDIATE INVENTORY
Close
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'
}