Commit acc88069 authored by Paul Kaplan's avatar Paul Kaplan

Allow curators to remove themselves

parent 31655d7f
...@@ -31,7 +31,15 @@ const selectCanEditOpenToAll = state => isManager(state); ...@@ -31,7 +31,15 @@ const selectCanEditOpenToAll = state => isManager(state);
const selectShowCuratorInvite = state => !!state.studio.invited; const selectShowCuratorInvite = state => !!state.studio.invited;
const selectCanInviteCurators = state => isManager(state); 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) => const selectCanRemoveManager = (state, managerId) =>
(selectIsAdmin(state) || isManager(state)) && managerId !== state.studio.owner; (selectIsAdmin(state) || isManager(state)) && managerId !== state.studio.owner;
const selectCanPromoteCurators = state => isManager(state); const selectCanPromoteCurators = state => isManager(state);
...@@ -63,7 +71,7 @@ export { ...@@ -63,7 +71,7 @@ export {
selectCanEditOpenToAll, selectCanEditOpenToAll,
selectShowCuratorInvite, selectShowCuratorInvite,
selectCanInviteCurators, selectCanInviteCurators,
selectCanRemoveCurators, selectCanRemoveCurator,
selectCanRemoveManager, selectCanRemoveManager,
selectCanPromoteCurators, selectCanPromoteCurators,
selectCanRemoveProject selectCanRemoveProject
......
...@@ -6,7 +6,7 @@ import classNames from 'classnames'; ...@@ -6,7 +6,7 @@ import classNames from 'classnames';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import { import {
selectCanRemoveCurators, selectCanRemoveManager, selectCanPromoteCurators selectCanRemoveCurator, selectCanRemoveManager, selectCanPromoteCurators
} from '../../redux/studio-permissions'; } from '../../redux/studio-permissions';
import { import {
promoteCurator, promoteCurator,
...@@ -109,8 +109,8 @@ const ManagerTile = connect( ...@@ -109,8 +109,8 @@ const ManagerTile = connect(
)(StudioMemberTile); )(StudioMemberTile);
const CuratorTile = connect( const CuratorTile = connect(
state => ({ (state, ownProps) => ({
canRemove: selectCanRemoveCurators(state), canRemove: selectCanRemoveCurator(state, ownProps.username),
canPromote: selectCanPromoteCurators(state) canPromote: selectCanPromoteCurators(state)
}), }),
{ {
......
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
selectCanEditOpenToAll, selectCanEditOpenToAll,
selectShowCuratorInvite, selectShowCuratorInvite,
selectCanInviteCurators, selectCanInviteCurators,
selectCanRemoveCurators, selectCanRemoveCurator,
selectCanRemoveManager, selectCanRemoveManager,
selectCanPromoteCurators, selectCanPromoteCurators,
selectCanRemoveProject selectCanRemoveProject
...@@ -287,7 +287,7 @@ describe('studio members', () => { ...@@ -287,7 +287,7 @@ describe('studio members', () => {
describe('can remove curators', () => { describe('can remove curators', () => {
test.each([ test.each([
['admin', true], ['admin', true],
['curator', false], ['curator', false], // except themselves, see test below
['manager', true], ['manager', true],
['creator', true], ['creator', true],
['logged in', false], ['logged in', false],
...@@ -295,7 +295,13 @@ describe('studio members', () => { ...@@ -295,7 +295,13 @@ describe('studio members', () => {
['logged out', false] ['logged out', false]
])('%s: %s', (role, expected) => { ])('%s: %s', (role, expected) => {
setStateByRole(role); 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);
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment