diff --git a/awx/ui/client/src/organizations/add/organizations-add.controller.js b/awx/ui/client/src/organizations/add/organizations-add.controller.js index 69fdfce1db..4b86b0db74 100644 --- a/awx/ui/client/src/organizations/add/organizations-add.controller.js +++ b/awx/ui/client/src/organizations/add/organizations-add.controller.js @@ -6,10 +6,10 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'OrganizationForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'GetBasePath', 'Wait', 'CreateSelect2', - '$state','InstanceGroupsService', 'ConfigData', 'MultiCredentialService', + '$state','InstanceGroupsService', 'ConfigData', 'MultiCredentialService', 'defaultGalaxyCredential', function($scope, $rootScope, $location, $stateParams, OrganizationForm, GenerateForm, Rest, Alert, ProcessErrors, GetBasePath, Wait, CreateSelect2, - $state, InstanceGroupsService, ConfigData, MultiCredentialService) { + $state, InstanceGroupsService, ConfigData, MultiCredentialService, defaultGalaxyCredential) { Rest.setUrl(GetBasePath('organizations')); Rest.options() @@ -38,6 +38,8 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Organizati // apply form definition's default field values GenerateForm.applyDefaults(form, $scope); + + $scope.credentials = defaultGalaxyCredential || []; } // Save diff --git a/awx/ui/client/src/organizations/galaxy-credentials-multiselect/galaxy-credentials-modal/galaxy-credentials-modal.directive.js b/awx/ui/client/src/organizations/galaxy-credentials-multiselect/galaxy-credentials-modal/galaxy-credentials-modal.directive.js index 145a835d88..c91726a570 100644 --- a/awx/ui/client/src/organizations/galaxy-credentials-multiselect/galaxy-credentials-modal/galaxy-credentials-modal.directive.js +++ b/awx/ui/client/src/organizations/galaxy-credentials-multiselect/galaxy-credentials-modal/galaxy-credentials-modal.directive.js @@ -49,7 +49,7 @@ export default ['templateUrl', '$window', function(templateUrl, $window) { credentialList.well = false; credentialList.multiSelect = true; credentialList.multiSelectPreview = { - selectedRows: 'igTags', + selectedRows: 'credTags', availableRows: 'credentials' }; credentialList.fields.name.ngClick = "linkoutCredential(credential)"; @@ -70,10 +70,10 @@ export default ['templateUrl', '$window', function(templateUrl, $window) { if ($scope.galaxyCredentials) { $scope.galaxyCredentials = $scope.galaxyCredentials.map( (item) => { item.isSelected = true; - if (!$scope.igTags) { - $scope.igTags = []; + if (!$scope.credTags) { + $scope.credTags = []; } - $scope.igTags.push(item); + $scope.credTags.push(item); return item; }); } @@ -83,7 +83,7 @@ export default ['templateUrl', '$window', function(templateUrl, $window) { $scope.$watch('credentials', function(){ angular.forEach($scope.credentials, function(credentialRow) { - angular.forEach($scope.igTags, function(selectedCredential){ + angular.forEach($scope.credTags, function(selectedCredential){ if(selectedCredential.id === credentialRow.id) { credentialRow.isSelected = true; } @@ -97,12 +97,12 @@ export default ['templateUrl', '$window', function(templateUrl, $window) { $scope.$on("selectedOrDeselected", function(e, value) { let item = value.value; if (value.isSelected) { - if(!$scope.igTags) { - $scope.igTags = []; + if(!$scope.credTags) { + $scope.credTags = []; } - $scope.igTags.push(item); + $scope.credTags.push(item); } else { - _.remove($scope.igTags, { id: item.id }); + _.remove($scope.credTags, { id: item.id }); } }); @@ -115,7 +115,7 @@ export default ['templateUrl', '$window', function(templateUrl, $window) { }; $scope.saveForm = function() { - $scope.galaxyCredentials = $scope.igTags; + $scope.galaxyCredentials = $scope.credTags; $scope.destroyModal(); }; }] diff --git a/awx/ui/client/src/organizations/main.js b/awx/ui/client/src/organizations/main.js index a831c13095..365f4e6e67 100644 --- a/awx/ui/client/src/organizations/main.js +++ b/awx/ui/client/src/organizations/main.js @@ -71,7 +71,29 @@ angular.module('Organizations', [ }); }); - }] + }], + defaultGalaxyCredential: ['Rest', 'GetBasePath', 'ProcessErrors', + function(Rest, GetBasePath, ProcessErrors){ + Rest.setUrl(GetBasePath('credentials')); + return Rest.get({ + params: { + credential_type__kind: 'galaxy', + managed_by_tower: true + } + }) + .then(({data}) => { + if (data.results.length > 0) { + return data.results; + } + }) + .catch(({data, status}) => { + ProcessErrors(null, data, status, null, { + hdr: 'Error!', + msg: 'Failed to get default Galaxy credential. GET returned ' + + 'status: ' + status + }); + }); + }], }, edit: { ConfigData: ['ConfigService', 'ProcessErrors', (ConfigService, ProcessErrors) => {