From 43574ab74ad0f6d9ae7e0d0df5b7584814dc0e81 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Mon, 19 Dec 2016 16:05:11 -0500 Subject: [PATCH] Fixed bug where adding a user to a team wasn't possible. Also fixed some other bugs with deleting permissions. --- .../rbac-resource.controller.js | 2 +- .../rbac-resource.directive.js | 1 + .../rbac-resource.partial.html | 7 +- .../rbac-role-column/roleList.directive.js | 57 ++++++++++++++-- .../rbac-role-column/roleList.partial.html | 2 +- awx/ui/client/src/app.js | 67 ------------------- awx/ui/client/src/shared/generator-helpers.js | 4 +- .../list-generator/list-generator.factory.js | 24 +++---- .../src/shared/stateDefinitions.factory.js | 45 ++++++++++++- 9 files changed, 116 insertions(+), 93 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 99cf7e9e11..e40589a3f6 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 @@ -84,7 +84,7 @@ export default ['$rootScope', '$scope', 'GetBasePath', 'Rest', '$q', 'Wait', 'Pr .map(function(role) { return { url: url, - id: role.value + 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 fde8ee4054..3bcdece9f6 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 @@ -15,6 +15,7 @@ export default ['templateUrl', '$state', usersDataset: '=', teamsDataset: '=', resourceData: '=', + withoutTeamPermissions: '@' }, controller: controller, templateUrl: templateUrl('access/add-rbac-resource/rbac-resource'), 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 e8c3361f91..75eaeb8302 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 @@ -39,16 +39,15 @@
+ ng-class="{'is-selected': teamsSelected }"> Teams
-
+
-
+
diff --git a/awx/ui/client/src/access/rbac-role-column/roleList.directive.js b/awx/ui/client/src/access/rbac-role-column/roleList.directive.js index 97682d0bc9..10b589cf7c 100644 --- a/awx/ui/client/src/access/rbac-role-column/roleList.directive.js +++ b/awx/ui/client/src/access/rbac-role-column/roleList.directive.js @@ -1,10 +1,12 @@ /* jshint unused: vars */ export default - [ 'templateUrl', - function(templateUrl) { + [ 'templateUrl', 'Wait', 'GetBasePath', 'Rest', '$state', 'ProcessErrors', 'Prompt', '$filter', '$rootScope', + function(templateUrl, Wait, GetBasePath, Rest, $state, ProcessErrors, Prompt, $filter, $rootScope) { return { restrict: 'E', - scope: true, + scope: { + 'deleteTarget': '=' + }, templateUrl: templateUrl('access/rbac-role-column/roleList'), link: function(scope, element, attrs) { // given a list of roles (things like "project @@ -12,12 +14,12 @@ export default // places in summary fields, and creates a // concatenated/sorted list scope.access_list = [] - .concat(scope.permission.summary_fields + .concat(scope.deleteTarget.summary_fields .direct_access.map((i) => { i.role.explicit = true; return i.role; })) - .concat(scope.permission.summary_fields + .concat(scope.deleteTarget.summary_fields .indirect_access.map((i) => { i.role.explicit = false; return i.role; @@ -34,6 +36,51 @@ export default return -1; } }); + + scope.deletePermission = function(user, accessListEntry) { + let entry = accessListEntry; + + let action = function() { + $('#prompt-modal').modal('hide'); + Wait('start'); + + let url; + if (entry.team_id) { + url = GetBasePath("teams") + entry.team_id + "/roles/"; + } else { + url = GetBasePath("users") + user.id + "/roles/"; + } + + Rest.setUrl(url); + Rest.post({ "disassociate": true, "id": entry.id }) + .success(function() { + Wait('stop'); + $state.go('.', null, { reload: true }); + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { + hdr: 'Error!', + msg: 'Failed to remove access. Call to ' + url + ' failed. DELETE returned status: ' + status + }); + }); + }; + + if (accessListEntry.team_id) { + Prompt({ + hdr: `Team access removal`, + body: `
Please confirm that you would like to remove ${entry.name} access from the team ${$filter('sanitize')(entry.team_name)}. This will affect all members of the team. If you would like to only remove access for this particular user, please remove them from the team.
`, + action: action, + actionText: 'REMOVE TEAM ACCESS' + }); + } else { + Prompt({ + hdr: `User access removal`, + body: `
Please confirm that you would like to remove ${entry.name} access from ${user.username}.
`, + action: action, + actionText: 'REMOVE' + }); + } + }; } }; } diff --git a/awx/ui/client/src/access/rbac-role-column/roleList.partial.html b/awx/ui/client/src/access/rbac-role-column/roleList.partial.html index 365a20f061..1a25afead0 100644 --- a/awx/ui/client/src/access/rbac-role-column/roleList.partial.html +++ b/awx/ui/client/src/access/rbac-role-column/roleList.partial.html @@ -2,7 +2,7 @@ ng-repeat="entry in access_list">
+ ng-click="deletePermission(deleteTarget, entry)">
diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 3d23bdcf8f..b2af552581 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -468,21 +468,6 @@ var tower = angular.module('Tower', [ } }); - - $stateExtender.addState({ - name: 'teamUsers', - url: '/teams/:team_id/users', - templateUrl: urlPrefix + 'partials/teams.html', - controller: UsersList, - resolve: { - Users: ['UsersList', 'QuerySet', '$stateParams', 'GetBasePath', (list, qs, $stateParams, GetBasePath) => { - let path = GetBasePath(list.basePath) || GetBasePath(list.name); - return qs.search(path, $stateParams[`${list.iterator}_search`]); - }] - } - }); - - $stateExtender.addState({ name: 'userCredentials', url: '/users/:user_id/credentials', @@ -514,58 +499,6 @@ var tower = angular.module('Tower', [ } }); - $rootScope.addPermission = function(scope) { - $compile("")(scope); - }; - $rootScope.addPermissionWithoutTeamTab = function(scope) { - $compile("")(scope); - }; - - $rootScope.deletePermission = function(user, accessListEntry) { - let entry = accessListEntry; - - let action = function() { - $('#prompt-modal').modal('hide'); - Wait('start'); - - let url; - if (entry.team_id) { - url = GetBasePath("teams") + entry.team_id + "/roles/"; - } else { - url = GetBasePath("users") + user.id + "/roles/"; - } - - Rest.setUrl(url); - Rest.post({ "disassociate": true, "id": entry.id }) - .success(function() { - Wait('stop'); - $state.go('.', null, { reload: true }); - }) - .error(function(data, status) { - ProcessErrors($rootScope, data, status, null, { - hdr: 'Error!', - msg: 'Failed to remove access. Call to ' + url + ' failed. DELETE returned status: ' + status - }); - }); - }; - - if (accessListEntry.team_id) { - Prompt({ - hdr: `Team access removal`, - body: `
Please confirm that you would like to remove ${entry.name} access from the team ${$filter('sanitize')(entry.team_name)}. This will affect all members of the team. If you would like to only remove access for this particular user, please remove them from the team.
`, - action: action, - actionText: 'REMOVE TEAM ACCESS' - }); - } else { - Prompt({ - hdr: `User access removal`, - body: `
Please confirm that you would like to remove ${entry.name} access from ${user.username}.
`, - action: action, - actionText: 'REMOVE' - }); - } - }; - $rootScope.deletePermissionFromUser = function(userId, userName, roleName, roleType, url) { var action = function() { $('#prompt-modal').modal('hide'); diff --git a/awx/ui/client/src/shared/generator-helpers.js b/awx/ui/client/src/shared/generator-helpers.js index 0b350639e2..3d12d2a627 100644 --- a/awx/ui/client/src/shared/generator-helpers.js +++ b/awx/ui/client/src/shared/generator-helpers.js @@ -467,7 +467,7 @@ angular.module('GeneratorHelpers', [systemStatus.name]) Attr(field, 'columnClass') : ""; html += ` - + `; @@ -476,7 +476,7 @@ angular.module('GeneratorHelpers', [systemStatus.name]) Attr(field, 'columnClass') : ""; html += ` - + `; diff --git a/awx/ui/client/src/shared/list-generator/list-generator.factory.js b/awx/ui/client/src/shared/list-generator/list-generator.factory.js index cac1e129aa..1c4214be44 100644 --- a/awx/ui/client/src/shared/list-generator/list-generator.factory.js +++ b/awx/ui/client/src/shared/list-generator/list-generator.factory.js @@ -489,18 +489,18 @@ export default ['$location', '$compile', '$rootScope', 'Attr', 'Icon', if (options.mode !== 'lookup'){ for (fld in list.fields) { - let customClass = list.fields[fld].columnClass || ''; - html += ` - `; + let customClass = list.fields[fld].columnClass || ''; + html += ` + `; } } if (options.mode === 'lookup') { diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index 2c3bb8c4cb..1ee7c2bdff 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -361,6 +361,44 @@ export default ['$injector', '$stateExtender', '$log', function($injector, $stat return states; } + function buildRbacUserDirective() { + let states = []; + + states.push($stateExtender.buildDefinition({ + name: `${formStateDefinition.name}.users.add`, + squashSearchUrl: true, + url: '/add-user', + params: { + user_search: { + value: { order_by: 'username', page_size: '5' }, + dynamic: true, + } + }, + views: { + [`modal@${formStateDefinition.name}`]: { + template: `` + } + }, + resolve: { + usersDataset: ['addPermissionsUsersList', 'QuerySet', '$stateParams', 'GetBasePath', + function(list, qs, $stateParams, GetBasePath) { + let path = GetBasePath(list.basePath) || GetBasePath(list.name); + return qs.search(path, $stateParams.user_search); + + } + ] + }, + onExit: function($state) { + if ($state.transition) { + $('#add-permissions-modal').modal('hide'); + $('.modal-backdrop').remove(); + $('body').removeClass('modal-open'); + } + }, + })); + return states; + } + function buildListNodes(field) { let states = []; states.push(buildListDefinition(field)); @@ -372,8 +410,13 @@ export default ['$injector', '$stateExtender', '$log', function($injector, $stat else { states.push(buildRbacResourceDirective()); } - states = _.flatten(states); } + else if (field.iterator === 'user' && field.actions && field.actions.add) { + if(form.name === 'team') { + states.push(buildRbacUserDirective()); + } + } + states = _.flatten(states); return states; }