From 8980e70918b24bfd1dff0d2080259e570ac80cec Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Fri, 29 Sep 2017 12:18:30 -0700 Subject: [PATCH] changing insights cred lookup to not use hard coded cred type and rather, do a comparison against the credential_type endpoint --- .../standard-inventory/inventory.form.js | 3 -- .../src/shared/stateDefinitions.factory.js | 33 +++++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) 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 67b862bc8a..d07b53ec8e 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 @@ -72,9 +72,6 @@ function(i18n, InventoryCompletedJobsList) { basePath: 'credentials', sourceModel: 'insights_credential', sourceField: 'name', - search: { - credential_type: '13' //insights - }, ngDisabled: '!(inventory_obj.summary_fields.user_capabilities.edit || canAdd) || !canEditOrg', }, instance_groups: { diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index 975dfb8416..62882bc3b3 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -722,7 +722,8 @@ function($injector, $stateExtender, $log, i18n) { function buildFieldDefinition(field) { // Some lookup modals require some additional default params, - // namely organization and inventory_script. If these params + // namely organization and inventory_script, and insights + // credentials. If these params // aren't set as default params out of the gate, then smart // search will think they need to be set as search tags. var params; @@ -739,6 +740,12 @@ function($injector, $stateExtender, $log, i18n) { organization: null }; } + else if(field.sourceModel === "insights_credential"){ + params = { + page_size: '5', + credential_type: null + }; + } else if(field.sourceModel === 'host') { params = { page_size: '5' @@ -805,8 +812,24 @@ function($injector, $stateExtender, $log, i18n) { return; } }], - Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', '$interpolate', '$rootScope', '$state', 'OrganizationId', - (list, qs, $stateParams, GetBasePath, $interpolate, $rootScope, $state, OrganizationId) => { + InsightsCredTypePK: ['ListDefinition', 'Rest', 'GetBasePath', 'ProcessErrors', + function(list, Rest, GetBasePath,ProcessErrors) { + if(list.iterator === 'insights_credential'){ + Rest.setUrl(GetBasePath('credential_types') + '?name=Insights'); + return Rest.get() + .then(({data}) => { + return data.results[0].id; + }) + .catch(({data, status}) => { + ProcessErrors(null, data, status, null, { + hdr: 'Error!', + msg: 'Failed to get credential type data: ' + status + }); + }); + } + }], + Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', '$interpolate', '$rootScope', '$state', 'OrganizationId', 'InsightsCredTypePK', + (list, qs, $stateParams, GetBasePath, $interpolate, $rootScope, $state, OrganizationId, InsightsCredTypePK) => { // allow lookup field definitions to use interpolated $stateParams / $rootScope in basePath field // the basePath on a form's lookup field will take precedence over the general model list's basepath let path, interpolator; @@ -830,6 +853,10 @@ function($injector, $stateExtender, $log, i18n) { $stateParams[`${list.iterator}_search`].role_level = "admin_role"; $stateParams[`${list.iterator}_search`].organization = OrganizationId; } + if(list.iterator === "insights_credential"){ + $stateParams[`${list.iterator}_search`].credential_type = InsightsCredTypePK.toString() ; + } + return qs.search(path, $stateParams[`${list.iterator}_search`]); }