diff --git a/src/redux/studio-permissions.js b/src/redux/studio-permissions.js index 0afdb2735..66eecdaa2 100644 --- a/src/redux/studio-permissions.js +++ b/src/redux/studio-permissions.js @@ -20,9 +20,11 @@ const selectShowCommentComposer = state => selectIsSocial(state); const selectCanReportComment = state => selectIsSocial(state); const selectCanRestoreComment = state => selectIsAdmin(state); // On the project page, project owners can delete comments with a confirmation, -// and admins can delete comments without a confirmation. For now, only admins -// can delete studio comments, so the following two are the same. -const selectCanDeleteComment = state => selectIsAdmin(state); +// and admins can delete comments without a confirmation. +// On the studio page, studio creators and managers have the ability to delete *their own* comments with confirmation. +// Admins can delete comments without a confirmation. +const selectCanDeleteAnyComment = state => selectIsAdmin(state); +const selectCanDeleteOwnComment = state => isCreator(state) || isManager(state); const selectCanDeleteCommentWithoutConfirm = state => selectIsAdmin(state); const selectCanFollowStudio = state => selectIsLoggedIn(state); @@ -77,7 +79,8 @@ export { selectCanAddProjects, selectCanFollowStudio, selectShowCommentComposer, - selectCanDeleteComment, + selectCanDeleteAnyComment, + selectCanDeleteOwnComment, selectCanDeleteCommentWithoutConfirm, selectCanReportComment, selectCanRestoreComment, diff --git a/src/views/studio/studio-comments.jsx b/src/views/studio/studio-comments.jsx index 22cda114c..949d1cc2d 100644 --- a/src/views/studio/studio-comments.jsx +++ b/src/views/studio/studio-comments.jsx @@ -10,10 +10,11 @@ import studioCommentActions from '../../redux/studio-comment-actions.js'; import StudioCommentsAllowed from './studio-comments-allowed.jsx'; import StudioCommentsNotAllowed from './studio-comments-not-allowed.jsx'; -import {selectIsAdmin, selectHasFetchedSession} from '../../redux/session'; +import {selectIsAdmin, selectHasFetchedSession, selectUsername} from '../../redux/session'; import { selectShowCommentComposer, - selectCanDeleteComment, + selectCanDeleteAnyComment, + selectCanDeleteOwnComment, selectCanDeleteCommentWithoutConfirm, selectCanReportComment, selectCanRestoreComment, @@ -32,7 +33,9 @@ const StudioComments = ({ replies, postURI, shouldShowCommentComposer, - canDeleteComment, + username, + canDeleteAnyComment, + canDeleteOwnComment, canDeleteCommentWithoutConfirm, canEditCommentsAllowed, canReportComment, @@ -88,7 +91,7 @@ const StudioComments = ({ { }); }); - describe('can delete comment', () => { + describe('can delete any comment', () => { test.each([ ['admin', true], ['curator', false], @@ -208,7 +209,26 @@ describe('studio comments', () => { ['muted logged in', false] ])('%s: %s', (role, expected) => { setStateByRole(role); - expect(selectCanDeleteComment(state)).toBe(expected); + expect(selectCanDeleteAnyComment(state)).toBe(expected); + }); + }); + + describe('can delete own comment', () => { + test.each([ + ['admin', false], // This is false here because we check for `canDeleteAnyComment` separately + ['curator', false], + ['manager', true], + ['creator', true], + ['logged in', false], + ['unconfirmed', false], + ['logged out', false], + ['muted creator', true], + ['muted manager', true], + ['muted curator', false], + ['muted logged in', false] + ])('%s: %s', (role, expected) => { + setStateByRole(role); + expect(selectCanDeleteOwnComment(state)).toBe(expected); }); });