From f3173dbe26bf02aa8634a5efd4f1d8c695c1ac9d Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Tue, 19 Mar 2019 12:08:36 -0400 Subject: [PATCH] address pr and product feedback --- .../rbac-resource.controller.js | 15 ++-- .../rbac-resource.directive.js | 1 + .../rbac-resource.partial.html | 6 +- .../linkout/addUsers/addUsers.controller.js | 6 +- .../src/shared/stateDefinitions.factory.js | 73 +++---------------- 5 files changed, 25 insertions(+), 76 deletions(-) diff --git a/awx/ui/client/src/access/add-rbac-resource/rbac-resource.controller.js b/awx/ui/client/src/access/add-rbac-resource/rbac-resource.controller.js index d79b22bda4..a49dba559a 100644 --- a/awx/ui/client/src/access/add-rbac-resource/rbac-resource.controller.js +++ b/awx/ui/client/src/access/add-rbac-resource/rbac-resource.controller.js @@ -119,11 +119,16 @@ export default ['$rootScope', '$scope', 'GetBasePath', 'Rest', '$q', 'Wait', 'Pr var url = GetBasePath(selectedValue.type + "s") + selectedValue.id + "/roles/"; - (selectedValue.roles || []) - .map(function(role) { - Rest.setUrl(url); - requests.push(Rest.post({ "id": role.value || role.id })); - }); + if (scope.onlyMemberRole === 'true') { + Rest.setUrl(url); + requests.push(Rest.post({ "id": scope.roles.member_role.id })); + } else { + (selectedValue.roles || []) + .map(function(role) { + Rest.setUrl(url); + requests.push(Rest.post({ "id": role.value || role.id })); + }); + } }); }); diff --git a/awx/ui/client/src/access/add-rbac-resource/rbac-resource.directive.js b/awx/ui/client/src/access/add-rbac-resource/rbac-resource.directive.js index c5ee969049..6076234c19 100644 --- a/awx/ui/client/src/access/add-rbac-resource/rbac-resource.directive.js +++ b/awx/ui/client/src/access/add-rbac-resource/rbac-resource.directive.js @@ -17,6 +17,7 @@ export default ['templateUrl', '$state', teamsDataset: '=', resourceData: '=', withoutTeamPermissions: '@', + onlyMemberRole: '@', title: '@' }, controller: controller, diff --git a/awx/ui/client/src/access/add-rbac-resource/rbac-resource.partial.html b/awx/ui/client/src/access/add-rbac-resource/rbac-resource.partial.html index 9779fc34f8..c7120913eb 100644 --- a/awx/ui/client/src/access/add-rbac-resource/rbac-resource.partial.html +++ b/awx/ui/client/src/access/add-rbac-resource/rbac-resource.partial.html @@ -20,7 +20,7 @@
- + 1
@@ -51,7 +51,7 @@
- +
@@ -110,7 +110,7 @@
diff --git a/awx/ui/client/src/organizations/linkout/addUsers/addUsers.controller.js b/awx/ui/client/src/organizations/linkout/addUsers/addUsers.controller.js index 7127efeed8..7e12d4b9b8 100644 --- a/awx/ui/client/src/organizations/linkout/addUsers/addUsers.controller.js +++ b/awx/ui/client/src/organizations/linkout/addUsers/addUsers.controller.js @@ -28,11 +28,9 @@ function($scope, $rootScope, ProcessErrors, GetBasePath, generateList, if ($scope.addType === 'Administrators') { Rest.setUrl(GetBasePath('organizations') + `${$state.params.organization_id}/object_roles`); Rest.get().then(({data}) => { - notAdminAlreadyParams.not__roles__in = data.results + notAdminAlreadyParams.not__roles = data.results .filter(({name}) => name === i18n._('Admin')) - .map(({id}) => id) - .join(','); - notAdminAlreadyParams.is_superuser = 'false'; + .map(({id}) => id)[0]; init(); }); } else { diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index 1a445cc83d..692fb03c50 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -591,83 +591,28 @@ function($injector, $stateExtender, $log, i18n) { }, views: { [`modal@${formStateDefinition.name}`]: { - template: `` + template: `` } }, ncyBreadcrumb:{ skip:true }, resolve: { - orgId: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath) { - let id; - if ($stateParams.team_id) { - Rest.setUrl(GetBasePath('teams') + `${$stateParams.team_id}`); - id = Rest.get().then(({data}) => { - return data.summary_fields.organization.id; - }); - } else { - id = null; - } - return id; - }], - teamRoles: ['$stateParams', 'Rest', 'GetBasePath', 'i18n', function($stateParams, Rest, GetBasePath, i18n) { - let roles = null; - if ($stateParams.team_id) { - const basePath = GetBasePath('teams') + `${$stateParams.team_id}/object_roles`; + roleToExclude: ['$stateParams', 'Rest', 'GetBasePath', 'i18n', function($stateParams, Rest, GetBasePath, i18n) { + const basePath = ($stateParams.team_id) ? GetBasePath('teams') + `${$stateParams.team_id}/object_roles` : + GetBasePath('organizations') + `${$stateParams.organization_id}/object_roles`; Rest.setUrl(basePath); - roles = Rest.get().then(({data}) => { - return data.results - .filter(({name}) => name === i18n._('Member') || name === i18n._('Admin')) - .map(({id}) => id) - .join(','); - }); - } - return roles; - }], - orgAdminRole: ['$stateParams', 'orgId', 'Rest', 'GetBasePath', 'i18n', - function($stateParams, orgId, Rest, GetBasePath, i18n) { - let orgIdToCheck = $stateParams.organization_id || orgId; - let role = null; - if (orgIdToCheck) { - const basePath = GetBasePath('organizations') + `${orgIdToCheck}/object_roles`; - Rest.setUrl(basePath); - role = Rest.get().then(({data}) => { - return data.results - .filter(({name}) => name === i18n._('Admin')) - .map(({id}) => id)[0]; - }); - } - return role; - }], - orgMemberRole: ['$stateParams', 'Rest', 'GetBasePath', 'i18n', function($stateParams, Rest, GetBasePath, i18n) { - let role = null; - if ($stateParams.organization_id) { - const basePath = GetBasePath('organizations') + `${$stateParams.organization_id}/object_roles`; - Rest.setUrl(basePath); - role = Rest.get().then(({data}) => { + return Rest.get().then(({data}) => { return data.results .filter(({name}) => name === i18n._('Member')) .map(({id}) => id)[0]; }); - } - return role; }], - rolesToExclude: ['teamRoles', 'orgAdminRole', 'orgMemberRole', '$stateParams', - function(teamRoles, orgAdminRole, orgMemberRole, $stateParams) { - let roles = null; - if ($stateParams.team_id) { - roles = `${teamRoles},${orgAdminRole}`; - } else if ($stateParams.organization_id) { - roles = `${orgAdminRole},${orgMemberRole}`; - } - return roles; - }], - usersDataset: ['addPermissionsUsersList', 'QuerySet', '$stateParams', 'GetBasePath', 'rolesToExclude', - function(list, qs, $stateParams, GetBasePath, rolesToExclude) { + usersDataset: ['addPermissionsUsersList', 'QuerySet', '$stateParams', 'GetBasePath', 'roleToExclude', + function(list, qs, $stateParams, GetBasePath, roleToExclude) { let path = GetBasePath(list.basePath) || GetBasePath(list.name); - if (rolesToExclude) { - $stateParams.add_user_search.not__roles__in = rolesToExclude; - $stateParams.add_user_search.is_superuser = 'false'; + if (roleToExclude) { + $stateParams.add_user_search.not__roles = roleToExclude; } return qs.search(path, $stateParams.add_user_search); }