From 6e2133aa5271411d034d38771e583077c6039ebf Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 9 Apr 2018 17:10:15 -0400 Subject: [PATCH] Limit adhoc credential lookup to only machine credentials --- .../inventories/adhoc/adhoc-credential.route.js | 3 ++- .../inventories/adhoc/adhoc.controller.js | 16 ++++++++++++++-- .../inventories/adhoc/adhoc.form.js | 1 + .../inventories/adhoc/adhoc.route.js | 9 +++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc-credential.route.js b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc-credential.route.js index 173c77f445..82f3321652 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc-credential.route.js +++ b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc-credential.route.js @@ -7,7 +7,8 @@ export default { params: { credential_search: { value: { - page_size: '5' + page_size: '5', + credential_type: null }, squash: true, dynamic: true diff --git a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.controller.js b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.controller.js index e5e020fc6d..33f3a0583f 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.controller.js @@ -12,7 +12,7 @@ function adhocController($q, $scope, $stateParams, $state, CheckPasswords, PromptForPasswords, CreateLaunchDialog, CreateSelect2, adhocForm, GenerateForm, Rest, ProcessErrors, GetBasePath, GetChoices, - KindChange, Wait, ParseTypeChange) { + KindChange, Wait, ParseTypeChange, credentialTypes) { // this is done so that we can access private functions for testing, but // we don't want to populate the "public" scope with these internal @@ -301,11 +301,23 @@ function adhocController($q, $scope, $stateParams, }); }; + $scope.lookupCredential = function(){ + let credType = _.filter(credentialTypes, function(credType){ + return credType.kind === "ssh"; + }); + $state.go('.credential', { + credential_search: { + credential_type: credType[0].id, + page_size: '5', + page: '1' + } + }); + }; } export default ['$q', '$scope', '$stateParams', '$state', 'CheckPasswords', 'PromptForPasswords', 'CreateLaunchDialog', 'CreateSelect2', 'adhocForm', 'GenerateForm', 'Rest', 'ProcessErrors', 'GetBasePath', - 'GetChoices', 'KindChange', 'Wait', 'ParseTypeChange', + 'GetChoices', 'KindChange', 'Wait', 'ParseTypeChange', 'credentialTypes', adhocController]; diff --git a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.form.js b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.form.js index 0799ff54c2..e3cd25263d 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.form.js +++ b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.form.js @@ -64,6 +64,7 @@ export default ['i18n', function(i18n) { sourceModel: 'credential', sourceField: 'name', class: 'squeeze', + ngClick: 'lookupCredential()', awPopOver: '

Select the credential you want to use when ' + 'accessing the remote hosts to run the command. ' + 'Choose the credential containing ' + diff --git a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.route.js b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.route.js index 3b96425d93..30d1f400a5 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.route.js +++ b/awx/ui/client/src/inventories-hosts/inventories/adhoc/adhoc.route.js @@ -26,5 +26,14 @@ export default { }, ncyBreadcrumb: { label: N_("RUN COMMAND") + }, + resolve: { + credentialTypes: ['CredentialTypeModel', (CredentialType) => + new CredentialType('get') + .then((model) => { + const credentialTypeRes = model.get(); + return credentialTypeRes.results; + }) + ] } };