1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Auto populate insights credential when creating insights project

This commit is contained in:
Michael Abashian 2017-06-22 15:04:00 -04:00
parent 04ca47ffab
commit 9947a59bcc
4 changed files with 39 additions and 12 deletions

View File

@ -116,9 +116,12 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm',
$scope.pathRequired = ($scope.scm_type.value === 'manual') ? true : false;
$scope.scmRequired = ($scope.scm_type.value !== 'manual') ? true : false;
$scope.scmBranchLabel = ($scope.scm_type.value === 'svn') ? 'Revision #' : 'SCM Branch';
// Dynamically update popover values
if ($scope.scm_type.value) {
if(($scope.lookupType === 'insights_credential' && $scope.scm_type.value !== 'insights') || ($scope.lookupType === 'scm_credential' && $scope.scm_type.value === 'insights')) {
$scope.credential = null;
$scope.credential_name = '';
}
switch ($scope.scm_type.value) {
case 'git':
$scope.credentialLabel = "SCM Credential";
@ -129,12 +132,16 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm',
'<p>' + i18n.sprintf(i18n._('%sNote:%s When using SSH protocol for GitHub or Bitbucket, enter an SSH key only, ' +
'do not enter a username (other than git). Additionally, GitHub and Bitbucket do not support password authentication when using ' +
'SSH. GIT read only protocol (git://) does not use username or password information.'), '<strong>', '</strong>');
$scope.credRequired = false;
$scope.lookupType = 'scm_credential';
break;
case 'svn':
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p>' + i18n._('Example URLs for Subversion SCM include:') + '</p>' +
'<ul class=\"no-bullets\"><li>https://github.com/ansible/ansible</li><li>svn://servername.example.com/path</li>' +
'<li>svn+ssh://servername.example.com/path</li></ul>';
$scope.credRequired = false;
$scope.lookupType = 'scm_credential';
break;
case 'hg':
$scope.credentialLabel = "SCM Credential";
@ -144,19 +151,24 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm',
'<p>' + i18n.sprintf(i18n._('%sNote:%s Mercurial does not support password authentication for SSH. ' +
'Do not put the username and key in the URL. ' +
'If using Bitbucket and SSH, do not supply your Bitbucket username.'), '<strong>', '</strong>');
$scope.credRequired = false;
$scope.lookupType = 'scm_credential';
break;
case 'insights':
$scope.pathRequired = false;
$scope.scmRequired = false;
$scope.credRequired = true;
$scope.credentialLabel = "Credential";
break;
$scope.lookupType = 'insights_credential';
break;
default:
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p> ' + i18n._('URL popover text') + '</p>';
$scope.credRequired = false;
$scope.lookupType = 'scm_credential';
}
}
}
}
};
$scope.formCancel = function() {
$state.go('projects');

View File

@ -251,6 +251,10 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
// Dynamically update popover values
if ($scope.scm_type.value) {
if(($scope.lookupType === 'insights_credential' && $scope.scm_type.value !== 'insights') || ($scope.lookupType === 'scm_credential' && $scope.scm_type.value === 'insights')) {
$scope.credential = null;
$scope.credential_name = '';
}
switch ($scope.scm_type.value) {
case 'git':
$scope.credentialLabel = "SCM Credential";
@ -259,12 +263,16 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
'<p>' + i18n.sprintf(i18n._('%sNote:%s When using SSH protocol for GitHub or Bitbucket, enter an SSH key only, ' +
'do not enter a username (other than git). Additionally, GitHub and Bitbucket do not support password authentication when using ' +
'SSH. GIT read only protocol (git://) does not use username or password information.'), '<strong>', '</strong>');
$scope.credRequired = false;
$scope.lookupType = 'scm_credential';
break;
case 'svn':
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p>' + i18n._('Example URLs for Subversion SCM include:') + '</p>' +
'<ul class=\"no-bullets\"><li>https://github.com/ansible/ansible</li><li>svn://servername.example.com/path</li>' +
'<li>svn+ssh://servername.example.com/path</li></ul>';
$scope.credRequired = false;
$scope.lookupType = 'scm_credential';
break;
case 'hg':
$scope.credentialLabel = "SCM Credential";
@ -274,16 +282,21 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
'<p>' + i18n.sprintf(i18n._('%sNote:%s Mercurial does not support password authentication for SSH. ' +
'Do not put the username and key in the URL. ' +
'If using Bitbucket and SSH, do not supply your Bitbucket username.'), '<strong>', '</strong>');
$scope.credRequired = false;
$scope.lookupType = 'scm_credential';
break;
case 'insights':
$scope.pathRequired = false;
$scope.scmRequired = false;
$scope.credRequired = true;
$scope.credentialLabel = "Credential";
break;
$scope.lookupType = 'insights_credential';
break;
default:
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p> ' + i18n._('URL popover text');
$scope.credRequired = false;
$scope.lookupType = 'scm_credential';
}
}
}

View File

@ -135,14 +135,13 @@ export default ['i18n', 'NotificationsList', function(i18n, NotificationsList) {
// kind: 'scm'
// },
ngClick: 'lookupCredential()',
autopopulateLookup: false,
awRequiredWhen: {
reqExpression: "credRequired",
init: false
},
ngShow: "scm_type && scm_type.value !== 'manual'",
sourceModel: 'credential',
awLookupType: 'scm_credential',
awLookupType: '{{lookupType}}',
sourceField: 'name',
ngDisabled: '!(project_obj.summary_fields.user_capabilities.edit || canAdd)',
subForm: 'sourceSubForm'

View File

@ -491,7 +491,6 @@ function(ConfigurationUtils, i18n, $rootScope) {
autopopulateLookup,
modelKey = attrs.ngModel,
modelName = attrs.source,
lookupType = attrs.awlookuptype,
watcher = attrs.awRequiredWhen || undefined,
watchBasePath,
awLookupWhen = attrs.awLookupWhen;
@ -534,16 +533,20 @@ function(ConfigurationUtils, i18n, $rootScope) {
}
else {
basePath = GetBasePath(elm.attr('data-basePath')) || elm.attr('data-basePath');
let switchType = lookupType ? lookupType : modelName;
let switchType = attrs.awlookuptype ? attrs.awlookuptype : modelName;console.log(switchType);
switch(switchType) {
case 'credential':
query = '?kind=ssh&role_level=use_role';
query = '?credential_type__kind=ssh&role_level=use_role';
break;
case 'scm_credential':
query = '?kind=scm&role_level=use_role';
query = '?credential_type__kind=scm&role_level=use_role';
break;
case 'network_credential':
query = '?kind=net&role_level=use_role';
query = '?credential_type__kind=net&role_level=use_role';
break;
case 'insights_credential':
query = '?credential_type__kind=insights&role_level=use_role';
break;
case 'organization':
query = '?role_level=admin_role';
@ -628,7 +631,7 @@ function(ConfigurationUtils, i18n, $rootScope) {
query = elm.attr('data-query');
query = query.replace(/\:value/, encodeURIComponent(viewValue));
let base = lookupType ? lookupType : ctrl.$name.split('_name')[0];
let base = attrs.awlookuptype ? attrs.awlookuptype : ctrl.$name.split('_name')[0];
if (attrs.watchbasepath !== undefined && scope[attrs.watchbasepath] !== undefined) {
basePath = scope[attrs.watchbasepath];
query += '&role_level=use_role';