mirror of
https://github.com/ansible/awx.git
synced 2026-04-07 11:09:22 -02:30
Merge pull request #2627 from jakemcdermott/fix-form-cred-lookups
fix project and adhoc command form lookups when many credential types exist Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
function adhocController($q, $scope, $stateParams,
|
function adhocController($q, $scope, $stateParams,
|
||||||
$state, CheckPasswords, PromptForPasswords, CreateLaunchDialog, CreateSelect2, adhocForm,
|
$state, CheckPasswords, PromptForPasswords, CreateLaunchDialog, CreateSelect2, adhocForm,
|
||||||
GenerateForm, Rest, ProcessErrors, GetBasePath, GetChoices,
|
GenerateForm, Rest, ProcessErrors, GetBasePath, GetChoices,
|
||||||
KindChange, Wait, ParseTypeChange, credentialTypes) {
|
KindChange, Wait, ParseTypeChange, machineCredentialType) {
|
||||||
|
|
||||||
// this is done so that we can access private functions for testing, but
|
// 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
|
// we don't want to populate the "public" scope with these internal
|
||||||
@@ -302,12 +302,9 @@ function adhocController($q, $scope, $stateParams,
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.lookupCredential = function(){
|
$scope.lookupCredential = function(){
|
||||||
let credType = _.filter(credentialTypes, function(credType){
|
|
||||||
return credType.kind === "ssh";
|
|
||||||
});
|
|
||||||
$state.go('.credential', {
|
$state.go('.credential', {
|
||||||
credential_search: {
|
credential_search: {
|
||||||
credential_type: credType[0].id,
|
credential_type: machineCredentialType,
|
||||||
page_size: '5',
|
page_size: '5',
|
||||||
page: '1'
|
page: '1'
|
||||||
}
|
}
|
||||||
@@ -319,5 +316,5 @@ function adhocController($q, $scope, $stateParams,
|
|||||||
export default ['$q', '$scope', '$stateParams',
|
export default ['$q', '$scope', '$stateParams',
|
||||||
'$state', 'CheckPasswords', 'PromptForPasswords', 'CreateLaunchDialog', 'CreateSelect2',
|
'$state', 'CheckPasswords', 'PromptForPasswords', 'CreateLaunchDialog', 'CreateSelect2',
|
||||||
'adhocForm', 'GenerateForm', 'Rest', 'ProcessErrors', 'GetBasePath',
|
'adhocForm', 'GenerateForm', 'Rest', 'ProcessErrors', 'GetBasePath',
|
||||||
'GetChoices', 'KindChange', 'Wait', 'ParseTypeChange', 'credentialTypes',
|
'GetChoices', 'KindChange', 'Wait', 'ParseTypeChange', 'machineCredentialType',
|
||||||
adhocController];
|
adhocController];
|
||||||
|
|||||||
@@ -7,6 +7,23 @@
|
|||||||
import {templateUrl} from '../../../shared/template-url/template-url.factory';
|
import {templateUrl} from '../../../shared/template-url/template-url.factory';
|
||||||
import { N_ } from '../../../i18n';
|
import { N_ } from '../../../i18n';
|
||||||
|
|
||||||
|
function ResolveMachineCredentialType (GetBasePath, Rest, ProcessErrors) {
|
||||||
|
Rest.setUrl(GetBasePath('credential_types') + '?kind=ssh');
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ResolveMachineCredentialType.$inject = ['GetBasePath', 'Rest', 'ProcessErrors'];
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
url: '/adhoc',
|
url: '/adhoc',
|
||||||
params:{
|
params:{
|
||||||
@@ -28,12 +45,6 @@ export default {
|
|||||||
label: N_("RUN COMMAND")
|
label: N_("RUN COMMAND")
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
credentialTypes: ['CredentialTypeModel', (CredentialType) =>
|
machineCredentialType: ResolveMachineCredentialType,
|
||||||
new CredentialType('get')
|
|
||||||
.then((model) => {
|
|
||||||
const credentialTypeRes = model.get();
|
|
||||||
return credentialTypeRes.results;
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,10 +7,10 @@
|
|||||||
export default ['$scope', '$location', '$stateParams', 'GenerateForm',
|
export default ['$scope', '$location', '$stateParams', 'GenerateForm',
|
||||||
'ProjectsForm', 'Rest', 'Alert', 'ProcessErrors', 'GetBasePath',
|
'ProjectsForm', 'Rest', 'Alert', 'ProcessErrors', 'GetBasePath',
|
||||||
'GetProjectPath', 'GetChoices', 'Wait', '$state', 'CreateSelect2', 'i18n',
|
'GetProjectPath', 'GetChoices', 'Wait', '$state', 'CreateSelect2', 'i18n',
|
||||||
'CredentialTypes', 'ConfigData', 'resolvedModels',
|
'ConfigData', 'resolvedModels', 'scmCredentialType',
|
||||||
function($scope, $location, $stateParams, GenerateForm, ProjectsForm, Rest,
|
function($scope, $location, $stateParams, GenerateForm, ProjectsForm, Rest,
|
||||||
Alert, ProcessErrors, GetBasePath, GetProjectPath, GetChoices, Wait, $state,
|
Alert, ProcessErrors, GetBasePath, GetProjectPath, GetChoices, Wait, $state,
|
||||||
CreateSelect2, i18n, CredentialTypes, ConfigData, resolvedModels) {
|
CreateSelect2, i18n, ConfigData, resolvedModels, scmCredentialType) {
|
||||||
|
|
||||||
let form = ProjectsForm(),
|
let form = ProjectsForm(),
|
||||||
base = $location.path().replace(/^\//, '').split('/')[0],
|
base = $location.path().replace(/^\//, '').split('/')[0],
|
||||||
@@ -191,13 +191,9 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm',
|
|||||||
$scope.lookupCredential = function(){
|
$scope.lookupCredential = function(){
|
||||||
// Perform a lookup on the credential_type. Git, Mercurial, and Subversion
|
// Perform a lookup on the credential_type. Git, Mercurial, and Subversion
|
||||||
// all use SCM as their credential type.
|
// all use SCM as their credential type.
|
||||||
let credType = _.filter(CredentialTypes, function(credType){
|
|
||||||
return ($scope.scm_type.value !== "insights" && credType.kind === "scm" ||
|
|
||||||
$scope.scm_type.value === "insights" && credType.kind === "insights");
|
|
||||||
});
|
|
||||||
$state.go('.credential', {
|
$state.go('.credential', {
|
||||||
credential_search: {
|
credential_search: {
|
||||||
credential_type: credType[0].id,
|
credential_type: scmCredentialType,
|
||||||
page_size: '5',
|
page_size: '5',
|
||||||
page: '1'
|
page: '1'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
|
|||||||
'Alert', 'ProcessErrors', 'GenerateForm', 'Prompt',
|
'Alert', 'ProcessErrors', 'GenerateForm', 'Prompt',
|
||||||
'GetBasePath', 'GetProjectPath', 'Authorization', 'GetChoices', 'Empty',
|
'GetBasePath', 'GetProjectPath', 'Authorization', 'GetChoices', 'Empty',
|
||||||
'Wait', 'ProjectUpdate', '$state', 'CreateSelect2', 'ToggleNotification',
|
'Wait', 'ProjectUpdate', '$state', 'CreateSelect2', 'ToggleNotification',
|
||||||
'i18n', 'CredentialTypes', 'OrgAdminLookup', 'ConfigData',
|
'i18n', 'OrgAdminLookup', 'ConfigData', 'scmCredentialType',
|
||||||
function($scope, $rootScope, $stateParams, ProjectsForm, Rest, Alert,
|
function($scope, $rootScope, $stateParams, ProjectsForm, Rest, Alert,
|
||||||
ProcessErrors, GenerateForm, Prompt, GetBasePath,
|
ProcessErrors, GenerateForm, Prompt, GetBasePath,
|
||||||
GetProjectPath, Authorization, GetChoices, Empty, Wait, ProjectUpdate,
|
GetProjectPath, Authorization, GetChoices, Empty, Wait, ProjectUpdate,
|
||||||
$state, CreateSelect2, ToggleNotification, i18n, CredentialTypes,
|
$state, CreateSelect2, ToggleNotification, i18n, OrgAdminLookup,
|
||||||
OrgAdminLookup, ConfigData) {
|
ConfigData, scmCredentialType) {
|
||||||
|
|
||||||
let form = ProjectsForm(),
|
let form = ProjectsForm(),
|
||||||
defaultUrl = GetBasePath('projects') + $stateParams.project_id + '/',
|
defaultUrl = GetBasePath('projects') + $stateParams.project_id + '/',
|
||||||
@@ -321,13 +321,10 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
|
|||||||
$scope.lookupCredential = function(){
|
$scope.lookupCredential = function(){
|
||||||
// Perform a lookup on the credential_type. Git, Mercurial, and Subversion
|
// Perform a lookup on the credential_type. Git, Mercurial, and Subversion
|
||||||
// all use SCM as their credential type.
|
// all use SCM as their credential type.
|
||||||
let credType = _.filter(CredentialTypes, function(credType){
|
|
||||||
return ($scope.scm_type.value !== "insights" && credType.kind === "scm" ||
|
|
||||||
$scope.scm_type.value === "insights" && credType.kind === "insights");
|
|
||||||
});
|
|
||||||
$state.go('.credential', {
|
$state.go('.credential', {
|
||||||
credential_search: {
|
credential_search: {
|
||||||
credential_type: credType[0].id,
|
credential_type: scmCredentialType,
|
||||||
page_size: '5',
|
page_size: '5',
|
||||||
page: '1'
|
page: '1'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,25 @@ import {
|
|||||||
import ProjectsTemplatesRoute from '~features/templates/routes/projectsTemplatesList.route';
|
import ProjectsTemplatesRoute from '~features/templates/routes/projectsTemplatesList.route';
|
||||||
import projectsListRoute from '~features/projects/routes/projectsList.route.js';
|
import projectsListRoute from '~features/projects/routes/projectsList.route.js';
|
||||||
|
|
||||||
|
|
||||||
|
function ResolveScmCredentialType (GetBasePath, Rest, ProcessErrors) {
|
||||||
|
Rest.setUrl(GetBasePath('credential_types') + '?kind=scm');
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ResolveScmCredentialType.$inject = ['GetBasePath', 'Rest', 'ProcessErrors'];
|
||||||
|
|
||||||
|
|
||||||
export default
|
export default
|
||||||
angular.module('Projects', [])
|
angular.module('Projects', [])
|
||||||
.controller('ProjectsAdd', ProjectsAdd)
|
.controller('ProjectsAdd', ProjectsAdd)
|
||||||
@@ -34,19 +53,29 @@ angular.module('Projects', [])
|
|||||||
let stateDefinitions = stateDefinitionsProvider.$get();
|
let stateDefinitions = stateDefinitionsProvider.$get();
|
||||||
let stateExtender = $stateExtenderProvider.$get();
|
let stateExtender = $stateExtenderProvider.$get();
|
||||||
|
|
||||||
|
const projectsAddName = 'projects.add';
|
||||||
|
const projectsEditName = 'projects.edit';
|
||||||
|
|
||||||
function generateStateTree() {
|
function generateStateTree() {
|
||||||
let projectAdd = stateDefinitions.generateTree({
|
let projectAdd = stateDefinitions.generateTree({
|
||||||
name: 'projects.add',
|
name: projectsAddName,
|
||||||
url: '/add',
|
url: '/add',
|
||||||
modes: ['add'],
|
modes: ['add'],
|
||||||
form: 'ProjectsForm',
|
form: 'ProjectsForm',
|
||||||
controllers: {
|
controllers: {
|
||||||
add: 'ProjectsAdd',
|
add: 'ProjectsAdd',
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
const stateIndex = res.states.findIndex(s => s.name === projectsAddName);
|
||||||
|
|
||||||
|
res.states[stateIndex].resolve.scmCredentialType = ResolveScmCredentialType;
|
||||||
|
|
||||||
|
return res;
|
||||||
});
|
});
|
||||||
|
|
||||||
let projectEdit = stateDefinitions.generateTree({
|
let projectEdit = stateDefinitions.generateTree({
|
||||||
name: 'projects.edit',
|
name: projectsEditName,
|
||||||
url: '/:project_id',
|
url: '/:project_id',
|
||||||
modes: ['edit'],
|
modes: ['edit'],
|
||||||
form: 'ProjectsForm',
|
form: 'ProjectsForm',
|
||||||
@@ -61,6 +90,13 @@ angular.module('Projects', [])
|
|||||||
breadcrumbs: {
|
breadcrumbs: {
|
||||||
edit: '{{breadcrumb.project_name}}'
|
edit: '{{breadcrumb.project_name}}'
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
const stateIndex = res.states.findIndex(s => s.name === projectsEditName);
|
||||||
|
|
||||||
|
res.states[stateIndex].resolve.scmCredentialType = ResolveScmCredentialType;
|
||||||
|
|
||||||
|
return res;
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
|||||||
Reference in New Issue
Block a user