mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 11:20:39 -03:30
Merge pull request #7205 from jlmitch5/credentialTypesLookup
Update credential types to lookup values instead of hardcode
This commit is contained in:
commit
4ead799fd0
@ -6,8 +6,8 @@
|
||||
|
||||
import jobSubmissionController from './job-submission.controller';
|
||||
|
||||
export default [ 'templateUrl', 'CreateDialog', 'Wait', 'CreateSelect2', 'ParseTypeChange', 'GetSurveyQuestions', 'i18n',
|
||||
function(templateUrl, CreateDialog, Wait, CreateSelect2, ParseTypeChange, GetSurveyQuestions, i18n) {
|
||||
export default [ 'templateUrl', 'CreateDialog', 'Wait', 'CreateSelect2', 'ParseTypeChange', 'GetSurveyQuestions', 'i18n', 'credentialTypesLookup',
|
||||
function(templateUrl, CreateDialog, Wait, CreateSelect2, ParseTypeChange, GetSurveyQuestions, i18n, credentialTypesLookup) {
|
||||
return {
|
||||
scope: {
|
||||
submitJobId: '=',
|
||||
@ -24,15 +24,18 @@ export default [ 'templateUrl', 'CreateDialog', 'Wait', 'CreateSelect2', 'ParseT
|
||||
scope.removeLaunchJobModalReady();
|
||||
}
|
||||
scope.removeLaunchJobModalReady = scope.$on('LaunchJobModalReady', function() {
|
||||
credentialTypesLookup()
|
||||
.then(kinds => {
|
||||
if(scope.ask_credential_on_launch) {
|
||||
scope.credentialKind = "" + kinds.SSH;
|
||||
scope.includeCredentialList = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Go get the list/survey data that we need from the server
|
||||
if(scope.ask_inventory_on_launch) {
|
||||
scope.includeInventoryList = true;
|
||||
}
|
||||
if(scope.ask_credential_on_launch) {
|
||||
scope.credentialKind = (scope.ask_credential_on_launch) ? "1" : "5";
|
||||
|
||||
scope.includeCredentialList = true;
|
||||
}
|
||||
if(scope.survey_enabled) {
|
||||
GetSurveyQuestions({
|
||||
scope: scope,
|
||||
|
||||
@ -5,8 +5,9 @@
|
||||
*************************************************/
|
||||
|
||||
export default
|
||||
[ '$scope', 'CredentialList', 'i18n', 'QuerySet', 'GetBasePath',
|
||||
function($scope, CredentialList, i18n, qs, GetBasePath) {
|
||||
[ '$scope', 'CredentialList', 'i18n', 'QuerySet', 'GetBasePath', 'credentialTypesLookup',
|
||||
function($scope, CredentialList, i18n, qs, GetBasePath, credentialTypesLookup) {
|
||||
let credentialKinds = {};
|
||||
|
||||
let updateExtraCredentialsList = function() {
|
||||
$scope.credentials.forEach((row, i) => {
|
||||
@ -69,9 +70,9 @@ export default
|
||||
|
||||
$scope.$watchCollection('selectedCredentials.extra', () => {
|
||||
if($scope.credentials && $scope.credentials.length > 0) {
|
||||
if($scope.selectedCredentials.extra && $scope.selectedCredentials.extra.length > 0 && parseInt($scope.credentialKind) !== 1) {
|
||||
if($scope.selectedCredentials.extra && $scope.selectedCredentials.extra.length > 0 && parseInt($scope.credentialKind) !== credentialKinds.SSH) {
|
||||
updateExtraCredentialsList();
|
||||
} else if (parseInt($scope.credentialKind) !== 1) {
|
||||
} else if (parseInt($scope.credentialKind) !== credentialKinds.SSH) {
|
||||
uncheckAllCredentials();
|
||||
}
|
||||
}
|
||||
@ -79,7 +80,7 @@ export default
|
||||
|
||||
$scope.$watch('selectedCredentials.machine', () => {
|
||||
if($scope.credentials && $scope.credentials.length > 0) {
|
||||
if($scope.selectedCredentials.machine && parseInt($scope.credentialKind) === 1) {
|
||||
if($scope.selectedCredentials.machine && parseInt($scope.credentialKind) === credentialKinds.SSH) {
|
||||
updateMachineCredentialList();
|
||||
}
|
||||
else {
|
||||
@ -90,10 +91,10 @@ export default
|
||||
|
||||
$scope.$watchGroup(['credentials', 'selectedCredentials.machine'], () => {
|
||||
if($scope.credentials && $scope.credentials.length > 0) {
|
||||
if($scope.selectedCredentials.machine && parseInt($scope.credentialKind) === 1) {
|
||||
if($scope.selectedCredentials.machine && parseInt($scope.credentialKind) === credentialKinds.SSH) {
|
||||
updateMachineCredentialList();
|
||||
}
|
||||
else if($scope.selectedCredentials.extra && $scope.selectedCredentials.extra.length > 0 && parseInt($scope.credentialKind) !== 1) {
|
||||
else if($scope.selectedCredentials.extra && $scope.selectedCredentials.extra.length > 0 && parseInt($scope.credentialKind) !== credentialKinds.SSH) {
|
||||
updateExtraCredentialsList();
|
||||
}
|
||||
else {
|
||||
@ -104,7 +105,7 @@ export default
|
||||
};
|
||||
|
||||
$scope.toggle_row = function(selectedRow) {
|
||||
if(parseInt($scope.credentialKind) === 1) {
|
||||
if(parseInt($scope.credentialKind) === credentialKinds.SSH) {
|
||||
$scope.selectedCredentials.machine = _.cloneDeep(selectedRow);
|
||||
}
|
||||
else {
|
||||
@ -117,6 +118,10 @@ export default
|
||||
}
|
||||
};
|
||||
|
||||
init();
|
||||
credentialTypesLookup()
|
||||
.then(kinds => {
|
||||
credentialKinds = kinds;
|
||||
init();
|
||||
});
|
||||
}
|
||||
];
|
||||
|
||||
21
awx/ui/client/src/shared/credentialTypesLookup.factory.js
Normal file
21
awx/ui/client/src/shared/credentialTypesLookup.factory.js
Normal file
@ -0,0 +1,21 @@
|
||||
export default ['Rest', 'GetBasePath', 'ProcessErrors',
|
||||
function(Rest, GetBasePath, ProcessErrors) {
|
||||
return function() {
|
||||
Rest.setUrl(GetBasePath('credential_types'));
|
||||
return Rest.get()
|
||||
.then(({data}) => {
|
||||
var val = {};
|
||||
data.results.forEach(type => {
|
||||
val[type.name] = type.id;
|
||||
});
|
||||
return val;
|
||||
})
|
||||
.catch(({data, status}) => {
|
||||
ProcessErrors(null, data, status, null, {
|
||||
hdr: 'Error!',
|
||||
msg: 'Failed to GET credential types. Returned status' +
|
||||
status
|
||||
});
|
||||
});
|
||||
};
|
||||
}];
|
||||
@ -33,6 +33,7 @@ import features from './features/main';
|
||||
import orgAdminLookup from './org-admin-lookup/main';
|
||||
import limitPanels from './limit-panels/main';
|
||||
import multiSelectPreview from './multi-select-preview/main';
|
||||
import credentialTypesLookup from './credentialTypesLookup.factory';
|
||||
import 'angular-duration-format';
|
||||
|
||||
export default
|
||||
@ -68,5 +69,6 @@ angular.module('shared', [listGenerator.name,
|
||||
])
|
||||
.factory('stateDefinitions', stateDefinitions)
|
||||
.factory('lodashAsPromised', lodashAsPromised)
|
||||
.factory('credentialTypesLookup', credentialTypesLookup)
|
||||
.directive('truncatedText', truncatedText)
|
||||
.provider('$stateExtender', stateExtender);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile', 'CreateSelect2', 'i18n', 'MultiCredentialService',
|
||||
function(templateUrl, Rest, GetBasePath, GenerateList, $compile, CreateSelect2, i18n, MultiCredentialService) {
|
||||
export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile', 'CreateSelect2', 'i18n', 'MultiCredentialService', 'credentialTypesLookup',
|
||||
function(templateUrl, Rest, GetBasePath, GenerateList, $compile, CreateSelect2, i18n, MultiCredentialService, credentialTypesLookup) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
@ -10,43 +10,48 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
templateUrl: templateUrl('templates/job_templates/multi-credential/multi-credential-modal'),
|
||||
|
||||
link: function(scope, element) {
|
||||
scope.credentialKind = "1";
|
||||
credentialTypesLookup()
|
||||
.then(kinds => {
|
||||
scope.credentialKinds = kinds;
|
||||
|
||||
scope.showModal = function() {
|
||||
$('#multi-credential-modal').modal('show');
|
||||
};
|
||||
scope.credentialKind = "" + kinds.SSH;
|
||||
|
||||
scope.destroyModal = function() {
|
||||
scope.credentialKind = 1;
|
||||
$('#multi-credential-modal').modal('hide');
|
||||
};
|
||||
scope.showModal = function() {
|
||||
$('#multi-credential-modal').modal('show');
|
||||
};
|
||||
|
||||
scope.generateCredentialList = function() {
|
||||
let html = GenerateList.build({
|
||||
list: scope.list,
|
||||
input_type: 'radio',
|
||||
mode: 'lookup'
|
||||
});
|
||||
$('#multi-credential-modal-body')
|
||||
.append($compile(html)(scope));
|
||||
};
|
||||
scope.destroyModal = function() {
|
||||
scope.credentialKind = kinds.SSH;
|
||||
$('#multi-credential-modal').modal('hide');
|
||||
};
|
||||
|
||||
$('#multi-credential-modal').on('hidden.bs.modal', function () {
|
||||
$('#multi-credential-modal').off('hidden.bs.modal');
|
||||
$(element).remove();
|
||||
});
|
||||
scope.generateCredentialList = function() {
|
||||
let html = GenerateList.build({
|
||||
list: scope.list,
|
||||
input_type: 'radio',
|
||||
mode: 'lookup'
|
||||
});
|
||||
$('#multi-credential-modal-body')
|
||||
.append($compile(html)(scope));
|
||||
};
|
||||
|
||||
CreateSelect2({
|
||||
element: `#multi-credential-kind-select`,
|
||||
multiple: false,
|
||||
placeholder: i18n._('Select a credential')
|
||||
});
|
||||
$('#multi-credential-modal').on('hidden.bs.modal', function () {
|
||||
$('#multi-credential-modal').off('hidden.bs.modal');
|
||||
$(element).remove();
|
||||
});
|
||||
|
||||
MultiCredentialService.getCredentialTypes()
|
||||
.then(({credential_types, credentialTypeOptions}) => {
|
||||
scope.credential_types = credential_types;
|
||||
scope.credentialTypeOptions = credentialTypeOptions;
|
||||
scope.$emit('multiCredentialModalLinked');
|
||||
CreateSelect2({
|
||||
element: `#multi-credential-kind-select`,
|
||||
multiple: false,
|
||||
placeholder: i18n._('Select a credential')
|
||||
});
|
||||
|
||||
MultiCredentialService.getCredentialTypes()
|
||||
.then(({credential_types, credentialTypeOptions}) => {
|
||||
scope.credential_types = credential_types;
|
||||
scope.credentialTypeOptions = credentialTypeOptions;
|
||||
scope.$emit('multiCredentialModalLinked');
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@ -57,7 +62,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
let extraCredIds = $scope.selectedCredentials.extra
|
||||
.map(cred => cred.id);
|
||||
$scope.credentials.forEach(cred => {
|
||||
if (cred.credential_type !== 1) {
|
||||
if (cred.credential_type !== $scope.credentialKinds.SSH) {
|
||||
cred.checked = (extraCredIds
|
||||
.indexOf(cred.id) > - 1) ? 1 : 0;
|
||||
}
|
||||
@ -70,7 +75,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
|
||||
let updateMachineCredentialList = function() {
|
||||
$scope.credentials.forEach(cred => {
|
||||
if (cred.credential_type === 1) {
|
||||
if (cred.credential_type === $scope.credentialKinds.SSH) {
|
||||
cred.checked = ($scope.selectedCredentials
|
||||
.machine !== null &&
|
||||
cred.id === $scope.selectedCredentials
|
||||
@ -85,7 +90,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
|
||||
let updateVaultCredentialList = function() {
|
||||
$scope.credentials.forEach(cred => {
|
||||
if (cred.credential_type === 3) {
|
||||
if (cred.credential_type === $scope.credentialKinds.Vault) {
|
||||
cred.checked = ($scope.selectedCredentials
|
||||
.vault !== null &&
|
||||
cred.id === $scope.selectedCredentials
|
||||
@ -153,9 +158,9 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
if($scope.credentials && $scope.credentials.length > 0) {
|
||||
if($scope.selectedCredentials.extra &&
|
||||
$scope.selectedCredentials.extra.length > 0 &&
|
||||
parseInt($scope.credentialKind) !== 1) {
|
||||
parseInt($scope.credentialKind) !== $scope.credentialKinds.SSH) {
|
||||
updateExtraCredentialsList();
|
||||
} else if (parseInt($scope.credentialKind) !== 1) {
|
||||
} else if (parseInt($scope.credentialKind) !== $scope.credentialKinds.SSH) {
|
||||
uncheckAllCredentials();
|
||||
}
|
||||
}
|
||||
@ -164,7 +169,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
$scope.$watch('selectedCredentials.machine', () => {
|
||||
if($scope.selectedCredentials &&
|
||||
$scope.selectedCredentials.machine &&
|
||||
parseInt($scope.credentialKind) === 1) {
|
||||
parseInt($scope.credentialKind) === $scope.credentialKinds.SSH) {
|
||||
updateMachineCredentialList();
|
||||
} else {
|
||||
uncheckAllCredentials();
|
||||
@ -174,7 +179,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
$scope.$watch('selectedCredentials.vault', () => {
|
||||
if($scope.selectedCredentials &&
|
||||
$scope.selectedCredentials.vault &&
|
||||
parseInt($scope.credentialKind) === 3) {
|
||||
parseInt($scope.credentialKind) === $scope.credentialKinds.Vault) {
|
||||
updateVaultCredentialList();
|
||||
} else {
|
||||
uncheckAllCredentials();
|
||||
@ -188,16 +193,16 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
$scope.credentials.length > 0) {
|
||||
if($scope.selectedCredentials &&
|
||||
$scope.selectedCredentials.machine &&
|
||||
parseInt($scope.credentialKind) === 1) {
|
||||
parseInt($scope.credentialKind) === $scope.credentialKinds.SSH) {
|
||||
updateMachineCredentialList();
|
||||
} else if($scope.selectedCredentials &&
|
||||
$scope.selectedCredentials.vault &&
|
||||
parseInt($scope.credentialKind) === 3) {
|
||||
parseInt($scope.credentialKind) === $scope.credentialKinds.Vault) {
|
||||
updateVaultCredentialList();
|
||||
} else if($scope.selectedCredentials &&
|
||||
$scope.selectedCredentials.extra &&
|
||||
$scope.selectedCredentials.extra.length > 0 &&
|
||||
parseInt($scope.credentialKind) !== 1) {
|
||||
parseInt($scope.credentialKind) !== $scope.credentialKinds.SSH) {
|
||||
updateExtraCredentialsList();
|
||||
} else {
|
||||
uncheckAllCredentials();
|
||||
@ -211,7 +216,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
});
|
||||
|
||||
$scope.toggle_row = function(selectedRow) {
|
||||
if(parseInt($scope.credentialKind) === 1) {
|
||||
if(parseInt($scope.credentialKind) === $scope.credentialKinds.SSH) {
|
||||
if($scope.selectedCredentials &&
|
||||
$scope.selectedCredentials.machine &&
|
||||
$scope.selectedCredentials.machine.id === selectedRow.id) {
|
||||
@ -219,7 +224,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
||||
} else {
|
||||
$scope.selectedCredentials.machine = _.cloneDeep(selectedRow);
|
||||
}
|
||||
}else if(parseInt($scope.credentialKind) === 3) {
|
||||
}else if(parseInt($scope.credentialKind) === $scope.credentialKinds.Vault) {
|
||||
if($scope.selectedCredentials &&
|
||||
$scope.selectedCredentials.vault &&
|
||||
$scope.selectedCredentials.vault.id === selectedRow.id) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user