From acc88069e9e735309236c9b1cd3c00f57903dd60 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 14 May 2021 12:37:05 -0400 Subject: [PATCH] Allow curators to remove themselves --- src/redux/studio-permissions.js | 12 ++++++++++-- src/views/studio/studio-member-tile.jsx | 6 +++--- test/unit/redux/studio-permissions.test.js | 12 +++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/redux/studio-permissions.js b/src/redux/studio-permissions.js index 7ce9f4905..25c445fe0 100644 --- a/src/redux/studio-permissions.js +++ b/src/redux/studio-permissions.js @@ -31,7 +31,15 @@ const selectCanEditOpenToAll = state => isManager(state); const selectShowCuratorInvite = state => !!state.studio.invited; const selectCanInviteCurators = state => isManager(state); -const selectCanRemoveCurators = state => isManager(state) || selectIsAdmin(state); +const selectCanRemoveCurator = (state, username) => { + // Admins/managers can remove any curators + if (isManager(state) || selectIsAdmin(state)) return true; + // Curators can remove themselves + if (selectUsername(state) === username) { + return true; + } + return false; +}; const selectCanRemoveManager = (state, managerId) => (selectIsAdmin(state) || isManager(state)) && managerId !== state.studio.owner; const selectCanPromoteCurators = state => isManager(state); @@ -63,7 +71,7 @@ export { selectCanEditOpenToAll, selectShowCuratorInvite, selectCanInviteCurators, - selectCanRemoveCurators, + selectCanRemoveCurator, selectCanRemoveManager, selectCanPromoteCurators, selectCanRemoveProject diff --git a/src/views/studio/studio-member-tile.jsx b/src/views/studio/studio-member-tile.jsx index 6b0f5d661..e14c3b4b4 100644 --- a/src/views/studio/studio-member-tile.jsx +++ b/src/views/studio/studio-member-tile.jsx @@ -6,7 +6,7 @@ import classNames from 'classnames'; import {FormattedMessage} from 'react-intl'; import { - selectCanRemoveCurators, selectCanRemoveManager, selectCanPromoteCurators + selectCanRemoveCurator, selectCanRemoveManager, selectCanPromoteCurators } from '../../redux/studio-permissions'; import { promoteCurator, @@ -109,8 +109,8 @@ const ManagerTile = connect( )(StudioMemberTile); const CuratorTile = connect( - state => ({ - canRemove: selectCanRemoveCurators(state), + (state, ownProps) => ({ + canRemove: selectCanRemoveCurator(state, ownProps.username), canPromote: selectCanPromoteCurators(state) }), { diff --git a/test/unit/redux/studio-permissions.test.js b/test/unit/redux/studio-permissions.test.js index a1f0069ce..dcad14c33 100644 --- a/test/unit/redux/studio-permissions.test.js +++ b/test/unit/redux/studio-permissions.test.js @@ -11,7 +11,7 @@ import { selectCanEditOpenToAll, selectShowCuratorInvite, selectCanInviteCurators, - selectCanRemoveCurators, + selectCanRemoveCurator, selectCanRemoveManager, selectCanPromoteCurators, selectCanRemoveProject @@ -287,7 +287,7 @@ describe('studio members', () => { describe('can remove curators', () => { test.each([ ['admin', true], - ['curator', false], + ['curator', false], // except themselves, see test below ['manager', true], ['creator', true], ['logged in', false], @@ -295,7 +295,13 @@ describe('studio members', () => { ['logged out', false] ])('%s: %s', (role, expected) => { setStateByRole(role); - expect(selectCanRemoveCurators(state)).toBe(expected); + expect(selectCanRemoveCurator(state, 'others-username')).toBe(expected); + }); + + test('curators can remove themselves', () => { + setStateByRole('curator'); + const loggedInUsername = selectUsername(state); + expect(selectCanRemoveCurator(state, loggedInUsername)).toBe(true); }); });