From 9947a59bcc3047e0d3a7571bcb619893319d949c Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Thu, 22 Jun 2017 15:04:00 -0400 Subject: [PATCH] Auto populate insights credential when creating insights project --- .../projects/add/projects-add.controller.js | 18 +++++++++++++++--- .../projects/edit/projects-edit.controller.js | 15 ++++++++++++++- awx/ui/client/src/projects/projects.form.js | 3 +-- awx/ui/client/src/shared/directives.js | 15 +++++++++------ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/awx/ui/client/src/projects/add/projects-add.controller.js b/awx/ui/client/src/projects/add/projects-add.controller.js index 6ab9fc43de..544c4a72af 100644 --- a/awx/ui/client/src/projects/add/projects-add.controller.js +++ b/awx/ui/client/src/projects/add/projects-add.controller.js @@ -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', '

' + 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.'), '', ''); + $scope.credRequired = false; + $scope.lookupType = 'scm_credential'; break; case 'svn': $scope.credentialLabel = "SCM Credential"; $scope.urlPopover = '

' + i18n._('Example URLs for Subversion SCM include:') + '

' + ''; + $scope.credRequired = false; + $scope.lookupType = 'scm_credential'; break; case 'hg': $scope.credentialLabel = "SCM Credential"; @@ -144,19 +151,24 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm', '

' + 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.'), '', ''); + $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 = '

' + i18n._('URL popover text') + '

'; + $scope.credRequired = false; + $scope.lookupType = 'scm_credential'; } } - } + } }; $scope.formCancel = function() { $state.go('projects'); diff --git a/awx/ui/client/src/projects/edit/projects-edit.controller.js b/awx/ui/client/src/projects/edit/projects-edit.controller.js index ea9b5622be..67980870a4 100644 --- a/awx/ui/client/src/projects/edit/projects-edit.controller.js +++ b/awx/ui/client/src/projects/edit/projects-edit.controller.js @@ -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', '

' + 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.'), '', ''); + $scope.credRequired = false; + $scope.lookupType = 'scm_credential'; break; case 'svn': $scope.credentialLabel = "SCM Credential"; $scope.urlPopover = '

' + i18n._('Example URLs for Subversion SCM include:') + '

' + ''; + $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', '

' + 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.'), '', ''); + $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 = '

' + i18n._('URL popover text'); + $scope.credRequired = false; + $scope.lookupType = 'scm_credential'; } } } diff --git a/awx/ui/client/src/projects/projects.form.js b/awx/ui/client/src/projects/projects.form.js index 7399546d68..ebfbcd97c0 100644 --- a/awx/ui/client/src/projects/projects.form.js +++ b/awx/ui/client/src/projects/projects.form.js @@ -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' diff --git a/awx/ui/client/src/shared/directives.js b/awx/ui/client/src/shared/directives.js index 6589d3b555..3699e57259 100644 --- a/awx/ui/client/src/shared/directives.js +++ b/awx/ui/client/src/shared/directives.js @@ -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';