mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Studio creators and managers can delete their own comments
This commit is contained in:
parent
a17919e561
commit
8821e0e865
3 changed files with 43 additions and 13 deletions
|
@ -20,9 +20,11 @@ const selectShowCommentComposer = state => selectIsSocial(state);
|
||||||
const selectCanReportComment = state => selectIsSocial(state);
|
const selectCanReportComment = state => selectIsSocial(state);
|
||||||
const selectCanRestoreComment = state => selectIsAdmin(state);
|
const selectCanRestoreComment = state => selectIsAdmin(state);
|
||||||
// On the project page, project owners can delete comments with a confirmation,
|
// On the project page, project owners can delete comments with a confirmation,
|
||||||
// and admins can delete comments without a confirmation. For now, only admins
|
// and admins can delete comments without a confirmation.
|
||||||
// can delete studio comments, so the following two are the same.
|
// On the studio page, studio creators and managers have the ability to delete *their own* comments with confirmation.
|
||||||
const selectCanDeleteComment = state => selectIsAdmin(state);
|
// 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 selectCanDeleteCommentWithoutConfirm = state => selectIsAdmin(state);
|
||||||
|
|
||||||
const selectCanFollowStudio = state => selectIsLoggedIn(state);
|
const selectCanFollowStudio = state => selectIsLoggedIn(state);
|
||||||
|
@ -77,7 +79,8 @@ export {
|
||||||
selectCanAddProjects,
|
selectCanAddProjects,
|
||||||
selectCanFollowStudio,
|
selectCanFollowStudio,
|
||||||
selectShowCommentComposer,
|
selectShowCommentComposer,
|
||||||
selectCanDeleteComment,
|
selectCanDeleteAnyComment,
|
||||||
|
selectCanDeleteOwnComment,
|
||||||
selectCanDeleteCommentWithoutConfirm,
|
selectCanDeleteCommentWithoutConfirm,
|
||||||
selectCanReportComment,
|
selectCanReportComment,
|
||||||
selectCanRestoreComment,
|
selectCanRestoreComment,
|
||||||
|
|
|
@ -10,10 +10,11 @@ import studioCommentActions from '../../redux/studio-comment-actions.js';
|
||||||
import StudioCommentsAllowed from './studio-comments-allowed.jsx';
|
import StudioCommentsAllowed from './studio-comments-allowed.jsx';
|
||||||
import StudioCommentsNotAllowed from './studio-comments-not-allowed.jsx';
|
import StudioCommentsNotAllowed from './studio-comments-not-allowed.jsx';
|
||||||
|
|
||||||
import {selectIsAdmin, selectHasFetchedSession} from '../../redux/session';
|
import {selectIsAdmin, selectHasFetchedSession, selectUsername} from '../../redux/session';
|
||||||
import {
|
import {
|
||||||
selectShowCommentComposer,
|
selectShowCommentComposer,
|
||||||
selectCanDeleteComment,
|
selectCanDeleteAnyComment,
|
||||||
|
selectCanDeleteOwnComment,
|
||||||
selectCanDeleteCommentWithoutConfirm,
|
selectCanDeleteCommentWithoutConfirm,
|
||||||
selectCanReportComment,
|
selectCanReportComment,
|
||||||
selectCanRestoreComment,
|
selectCanRestoreComment,
|
||||||
|
@ -32,7 +33,9 @@ const StudioComments = ({
|
||||||
replies,
|
replies,
|
||||||
postURI,
|
postURI,
|
||||||
shouldShowCommentComposer,
|
shouldShowCommentComposer,
|
||||||
canDeleteComment,
|
username,
|
||||||
|
canDeleteAnyComment,
|
||||||
|
canDeleteOwnComment,
|
||||||
canDeleteCommentWithoutConfirm,
|
canDeleteCommentWithoutConfirm,
|
||||||
canEditCommentsAllowed,
|
canEditCommentsAllowed,
|
||||||
canReportComment,
|
canReportComment,
|
||||||
|
@ -88,7 +91,7 @@ const StudioComments = ({
|
||||||
<TopLevelComment
|
<TopLevelComment
|
||||||
hasThreadLimit
|
hasThreadLimit
|
||||||
author={comment.author}
|
author={comment.author}
|
||||||
canDelete={canDeleteComment}
|
canDelete={canDeleteAnyComment || (canDeleteOwnComment && comment.author.username === username)}
|
||||||
canDeleteWithoutConfirm={canDeleteCommentWithoutConfirm}
|
canDeleteWithoutConfirm={canDeleteCommentWithoutConfirm}
|
||||||
canReply={shouldShowCommentComposer}
|
canReply={shouldShowCommentComposer}
|
||||||
canReport={canReportComment}
|
canReport={canReportComment}
|
||||||
|
@ -136,7 +139,9 @@ StudioComments.propTypes = {
|
||||||
moreCommentsToLoad: PropTypes.bool,
|
moreCommentsToLoad: PropTypes.bool,
|
||||||
replies: PropTypes.shape({}),
|
replies: PropTypes.shape({}),
|
||||||
shouldShowCommentComposer: PropTypes.bool,
|
shouldShowCommentComposer: PropTypes.bool,
|
||||||
canDeleteComment: PropTypes.bool,
|
username: PropTypes.string,
|
||||||
|
canDeleteAnyComment: PropTypes.bool,
|
||||||
|
canDeleteOwnComment: PropTypes.bool,
|
||||||
canDeleteCommentWithoutConfirm: PropTypes.bool,
|
canDeleteCommentWithoutConfirm: PropTypes.bool,
|
||||||
canEditCommentsAllowed: PropTypes.bool,
|
canEditCommentsAllowed: PropTypes.bool,
|
||||||
canReportComment: PropTypes.bool,
|
canReportComment: PropTypes.bool,
|
||||||
|
@ -160,9 +165,11 @@ export default connect(
|
||||||
isAdmin: selectIsAdmin(state),
|
isAdmin: selectIsAdmin(state),
|
||||||
moreCommentsToLoad: state.comments.moreCommentsToLoad,
|
moreCommentsToLoad: state.comments.moreCommentsToLoad,
|
||||||
replies: state.comments.replies,
|
replies: state.comments.replies,
|
||||||
|
username: selectUsername(state),
|
||||||
commentsAllowed: selectStudioCommentsAllowed(state),
|
commentsAllowed: selectStudioCommentsAllowed(state),
|
||||||
shouldShowCommentComposer: selectShowCommentComposer(state),
|
shouldShowCommentComposer: selectShowCommentComposer(state),
|
||||||
canDeleteComment: selectCanDeleteComment(state),
|
canDeleteAnyComment: selectCanDeleteAnyComment(state),
|
||||||
|
canDeleteOwnComment: selectCanDeleteOwnComment(state),
|
||||||
canDeleteCommentWithoutConfirm: selectCanDeleteCommentWithoutConfirm(state),
|
canDeleteCommentWithoutConfirm: selectCanDeleteCommentWithoutConfirm(state),
|
||||||
canEditCommentsAllowed: selectCanEditCommentsAllowed(state),
|
canEditCommentsAllowed: selectCanEditCommentsAllowed(state),
|
||||||
canReportComment: selectCanReportComment(state),
|
canReportComment: selectCanReportComment(state),
|
||||||
|
|
|
@ -2,7 +2,8 @@ import {
|
||||||
selectCanEditInfo,
|
selectCanEditInfo,
|
||||||
selectCanAddProjects,
|
selectCanAddProjects,
|
||||||
selectShowCommentComposer,
|
selectShowCommentComposer,
|
||||||
selectCanDeleteComment,
|
selectCanDeleteAnyComment,
|
||||||
|
selectCanDeleteOwnComment,
|
||||||
selectCanDeleteCommentWithoutConfirm,
|
selectCanDeleteCommentWithoutConfirm,
|
||||||
selectCanReportComment,
|
selectCanReportComment,
|
||||||
selectCanRestoreComment,
|
selectCanRestoreComment,
|
||||||
|
@ -195,7 +196,7 @@ describe('studio comments', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('can delete comment', () => {
|
describe('can delete any comment', () => {
|
||||||
test.each([
|
test.each([
|
||||||
['admin', true],
|
['admin', true],
|
||||||
['curator', false],
|
['curator', false],
|
||||||
|
@ -208,7 +209,26 @@ describe('studio comments', () => {
|
||||||
['muted logged in', false]
|
['muted logged in', false]
|
||||||
])('%s: %s', (role, expected) => {
|
])('%s: %s', (role, expected) => {
|
||||||
setStateByRole(role);
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue