From 60a1f3ac891948c43456620f5acaa7408b6993c6 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Mon, 24 Jul 2017 17:07:41 -0400 Subject: [PATCH 1/8] Add the user action constants for removing all roles at a space level --- static_src/constants.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/static_src/constants.js b/static_src/constants.js index d3231549..05b815f6 100644 --- a/static_src/constants.js +++ b/static_src/constants.js @@ -270,6 +270,10 @@ const userActionTypes = keymirror({ USER_INVITE_ERROR: null, // Action to dismiss an user list notification. USER_LIST_NOTICE_DISMISSED: null, + // Action to remove all roles for space user. + USER_REMOVE_ALL_SPACE_ROLES: null, + // Action to removed all roles for space user. + USER_REMOVED_ALL_SPACE_ROLES: null, // Action to delete a user from an org. USER_DELETE: null, // Action when a user was deleted from an org on the server. From f17dfb1b02f278a95e6351da7866d602afb9b4eb Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Mon, 24 Jul 2017 17:08:01 -0400 Subject: [PATCH 2/8] Create the response to a user role change, so the UI updates --- static_src/stores/user_store.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/static_src/stores/user_store.js b/static_src/stores/user_store.js index 18520812..efe2e775 100644 --- a/static_src/stores/user_store.js +++ b/static_src/stores/user_store.js @@ -164,6 +164,13 @@ export class UserStore extends BaseStore { break; } + case userActionTypes.USER_REMOVED_ALL_SPACE_ROLES: { + this.delete(action.userGuid, (changed) => { + if (changed) this.emitChange(); + }); + break; + } + case userActionTypes.ERROR_REMOVE_USER: { this._error = action.error; this.emitChange(); From 2dfc2229c84b0b57ee90ba7b283243b607291189 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Mon, 24 Jul 2017 17:08:22 -0400 Subject: [PATCH 3/8] Create new user actions so that the user role changes can be replied to --- static_src/actions/user_actions.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/static_src/actions/user_actions.js b/static_src/actions/user_actions.js index 13a4de62..4cc192f3 100644 --- a/static_src/actions/user_actions.js +++ b/static_src/actions/user_actions.js @@ -90,6 +90,28 @@ const userActions = { .then((spaceUsers) => userActions.deleteUserOrDisplayNotice(spaceUsers, userGuid, orgGuid)); }, + removeAllSpaceRoles(userGuid, spaceGuid) { + AppDispatcher.handleViewAction({ + type: userActionTypes.USER_REMOVE_ALL_SPACE_ROLES, + userGuid, + spaceGuid + }); + + const spaceRoles = ['auditors', 'developers', 'managers']; + Promise.all(spaceRoles.map((role) => { + Promise.resolve(cfApi.deleteSpaceUserPermissions(userGuid, spaceGuid, role)); + })) + .then((responses) => userActions.handleSpaceRolesRemoved(responses, userGuid)); + }, + + handleSpaceRolesRemoved(responses, userGuid) { + AppDispatcher.handleViewAction({ + type: userActionTypes.USER_REMOVED_ALL_SPACE_ROLES, + responses, + userGuid + }); + }, + deleteUser(userGuid, orgGuid) { AppDispatcher.handleViewAction({ type: userActionTypes.USER_DELETE, From 459529ef0794e4a7bef0ed34037011a4196c4a79 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Mon, 24 Jul 2017 17:08:34 -0400 Subject: [PATCH 4/8] Add space based action items --- static_src/components/user_list.jsx | 8 +++++++- static_src/components/users.jsx | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/static_src/components/user_list.jsx b/static_src/components/user_list.jsx index de89940e..a9c8369e 100644 --- a/static_src/components/user_list.jsx +++ b/static_src/components/user_list.jsx @@ -130,6 +130,7 @@ export default class UserList extends React.Component { } render() { + let buttonText; let content =
; if (this.props.empty) { @@ -147,12 +148,17 @@ export default class UserList extends React.Component { if (this.props.onRemove) { let button = ; if (this.props.currentUserAccess) { + if (this.props.userType === 'org_users') { + buttonText = 'Remove User From Org'; + } else if (this.props.userType === 'space_users') { + buttonText = 'Remove All Space Roles'; + } button = ( - Remove User From Org + { buttonText } ); } diff --git a/static_src/components/users.jsx b/static_src/components/users.jsx index 7cb1063d..c1a8a109 100644 --- a/static_src/components/users.jsx +++ b/static_src/components/users.jsx @@ -106,6 +106,11 @@ export default class Users extends React.Component { userActions.deleteUser(userGuid, this.state.currentOrgGuid); } + handleRemoveSpaceRoles(userGuid, ev) { + ev.preventDefault(); + userActions.removeAllSpaceRoles(userGuid, this.entityGuid); + } + get entityType() { return this.state.currentType === ORG_NAME ? 'org' : 'space'; } @@ -125,6 +130,8 @@ export default class Users extends React.Component { if (this.state.currentType === ORG_NAME) { removeHandler = this.handleRemove; + } else if (this.state.currentType === SPACE_NAME) { + removeHandler = this.handleRemoveSpaceRoles; } let content = ( Date: Mon, 24 Jul 2017 17:41:12 -0400 Subject: [PATCH 5/8] Create working tests --- static_src/actions/user_actions.js | 9 ++--- .../test/unit/actions/user_actions.spec.js | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/static_src/actions/user_actions.js b/static_src/actions/user_actions.js index 4cc192f3..0e762150 100644 --- a/static_src/actions/user_actions.js +++ b/static_src/actions/user_actions.js @@ -98,10 +98,11 @@ const userActions = { }); const spaceRoles = ['auditors', 'developers', 'managers']; - Promise.all(spaceRoles.map((role) => { - Promise.resolve(cfApi.deleteSpaceUserPermissions(userGuid, spaceGuid, role)); - })) - .then((responses) => userActions.handleSpaceRolesRemoved(responses, userGuid)); + const spaceRemovalRequests = spaceRoles.map((role) => + Promise.resolve(cfApi.deleteSpaceUserPermissions(userGuid, spaceGuid, role)) + ); + return Promise.all(spaceRemovalRequests) + .then((responses) => userActions.handleSpaceRolesRemoved(responses, userGuid)); }, handleSpaceRolesRemoved(responses, userGuid) { diff --git a/static_src/test/unit/actions/user_actions.spec.js b/static_src/test/unit/actions/user_actions.spec.js index d91dc573..78a40c5c 100644 --- a/static_src/test/unit/actions/user_actions.spec.js +++ b/static_src/test/unit/actions/user_actions.spec.js @@ -208,6 +208,42 @@ describe('userActions', function() { }); }); + describe('removeAllSpaceRoles()', function() { + let userGuid; + let spaceGuid; + let user; + let spy; + let expectedParams; + + beforeEach(function (done) { + spy = setupViewSpy(sandbox); + userGuid = 'user-guid'; + spaceGuid = 'space-guid'; + user = { guid: userGuid }; + expectedParams = { userGuid, spaceGuid } + + sandbox.stub(cfApi, 'deleteSpaceUserPermissions') + .returns(Promise.resolve({})); + + sandbox.stub(userActions, 'handleSpaceRolesRemoved'); + + userActions.removeAllSpaceRoles(userGuid, spaceGuid).then(done, done.fail); + }); + + it('should dispatch a view event for USER_REMOVE_ALL_SPACE_ROLES', + function() { + assertAction(spy, userActionTypes.USER_REMOVE_ALL_SPACE_ROLES, expectedParams); + }); + + it(`should call cfApi.deleteSpaceUserPermissions`, function() { + expect(cfApi.deleteSpaceUserPermissions).toHaveBeenCalledThrice(); + }); + + it(`should call userActions.handleSpaceRolesRemoved`, function() { + expect(userActions.handleSpaceRolesRemoved).toHaveBeenCalledOnce(); + }); + }); + describe('deleteUserIfNoSpaceAssociation()', function() { let userGuid; let orgGuid; From dce8cf7dfcf816923d9fa2a5b77a123f154f1e37 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 25 Jul 2017 10:17:20 -0400 Subject: [PATCH 6/8] Save the changes around the constants --- static_src/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static_src/constants.js b/static_src/constants.js index 05b815f6..f544014c 100644 --- a/static_src/constants.js +++ b/static_src/constants.js @@ -270,7 +270,7 @@ const userActionTypes = keymirror({ USER_INVITE_ERROR: null, // Action to dismiss an user list notification. USER_LIST_NOTICE_DISMISSED: null, - // Action to remove all roles for space user. + // Action when all roles for space user are removed. USER_REMOVE_ALL_SPACE_ROLES: null, // Action to removed all roles for space user. USER_REMOVED_ALL_SPACE_ROLES: null, From 1c9a47d995b1350570f89ff6c6339c47bc7e03fe Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 25 Jul 2017 10:17:32 -0400 Subject: [PATCH 7/8] Add a test to check for user manipulation --- .../test/unit/stores/user_store.spec.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/static_src/test/unit/stores/user_store.spec.js b/static_src/test/unit/stores/user_store.spec.js index 8bb480a1..1cf47eb3 100644 --- a/static_src/test/unit/stores/user_store.spec.js +++ b/static_src/test/unit/stores/user_store.spec.js @@ -439,6 +439,55 @@ describe('UserStore', function () { }); }); + describe('on user spaces roles remove', function() { + let spaceGuid; + beforeEach(() => { + spaceGuid = 'space-guid'; + }); + + it('should remove the user of the guid from the data', function() { + var expectedUserGuid = 'zxkvnakjdva', + expectedUser = { guid: expectedUserGuid }; + + UserStore._data.push(expectedUser); + + userActions.removeAllSpaceRoles(expectedUserGuid, spaceGuid); + + expect(UserStore.get(expectedUserGuid)).toBeFalsy(); + }); + }); + + describe('on user spaces roles removed', function() { + it('should remove the user of the guid from the data', function() { + var expectedUserGuid = 'zxkvnakjdva', + expectedUser = { guid: expectedUserGuid }; + + UserStore._data.push(expectedUser); + + userActions.handleSpaceRolesRemoved(['random-response'], expectedUserGuid); + + expect(UserStore.get(expectedUserGuid)).toBeFalsy(); + }); + + it('should emit a change event if it deletes something', function() { + var spy = sandbox.spy(UserStore, 'emitChange'), + testUserGuid = 'qpweoiralkfdsj'; + + UserStore._data = Immutable.fromJS([{guid: testUserGuid}]); + userActions.handleSpaceRolesRemoved(['random-response'], testUserGuid); + + expect(spy).toHaveBeenCalledOnce(); + }); + + it('should not emit a change event if nothing deleted', function() { + var spy = sandbox.spy(UserStore, 'emitChange'); + + userActions.handleSpaceRolesRemoved(['random-response'], 'asdfljk'); + + expect(spy).not.toHaveBeenCalledOnce(); + }); + }); + describe('on user deleted', function() { it('should remove the user of the guid from the data', function() { var expectedUserGuid = 'zxkvnakjdva', From 2c2b8d4cc210e6f5eaa4c94bcb56b6883a2713b0 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 25 Jul 2017 10:36:13 -0400 Subject: [PATCH 8/8] Move the comment to correct action --- static_src/constants.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static_src/constants.js b/static_src/constants.js index f544014c..77185d4e 100644 --- a/static_src/constants.js +++ b/static_src/constants.js @@ -270,9 +270,9 @@ const userActionTypes = keymirror({ USER_INVITE_ERROR: null, // Action to dismiss an user list notification. USER_LIST_NOTICE_DISMISSED: null, - // Action when all roles for space user are removed. + // Action to remove all roles for space user. USER_REMOVE_ALL_SPACE_ROLES: null, - // Action to removed all roles for space user. + // Action when all roles for space user are removed. USER_REMOVED_ALL_SPACE_ROLES: null, // Action to delete a user from an org. USER_DELETE: null,