Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
8821e0e8
Commit
8821e0e8
authored
Jun 16, 2021
by
Karishma Chadha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Studio creators and managers can delete their own comments
parent
a17919e5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
13 deletions
+43
-13
src/redux/studio-permissions.js
src/redux/studio-permissions.js
+7
-4
src/views/studio/studio-comments.jsx
src/views/studio/studio-comments.jsx
+13
-6
test/unit/redux/studio-permissions.test.js
test/unit/redux/studio-permissions.test.js
+23
-3
No files found.
src/redux/studio-permissions.js
View file @
8821e0e8
...
@@ -20,9 +20,11 @@ const selectShowCommentComposer = state => selectIsSocial(state);
...
@@ -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 {
...
@@ -77,7 +79,8 @@ export {
selectCanAddProjects
,
selectCanAddProjects
,
selectCanFollowStudio
,
selectCanFollowStudio
,
selectShowCommentComposer
,
selectShowCommentComposer
,
selectCanDeleteComment
,
selectCanDeleteAnyComment
,
selectCanDeleteOwnComment
,
selectCanDeleteCommentWithoutConfirm
,
selectCanDeleteCommentWithoutConfirm
,
selectCanReportComment
,
selectCanReportComment
,
selectCanRestoreComment
,
selectCanRestoreComment
,
...
...
src/views/studio/studio-comments.jsx
View file @
8821e0e8
...
@@ -10,10 +10,11 @@ import studioCommentActions from '../../redux/studio-comment-actions.js';
...
@@ -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 = ({
...
@@ -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 = ({
...
@@ -88,7 +91,7 @@ const StudioComments = ({
<
TopLevelComment
<
TopLevelComment
hasThreadLimit
hasThreadLimit
author=
{
comment
.
author
}
author=
{
comment
.
author
}
canDelete=
{
canDelete
Comment
}
canDelete=
{
canDelete
AnyComment
||
(
canDeleteOwnComment
&&
comment
.
author
.
username
===
username
)
}
canDeleteWithoutConfirm=
{
canDeleteCommentWithoutConfirm
}
canDeleteWithoutConfirm=
{
canDeleteCommentWithoutConfirm
}
canReply=
{
shouldShowCommentComposer
}
canReply=
{
shouldShowCommentComposer
}
canReport=
{
canReportComment
}
canReport=
{
canReportComment
}
...
@@ -136,7 +139,9 @@ StudioComments.propTypes = {
...
@@ -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(
...
@@ -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
),
...
...
test/unit/redux/studio-permissions.test.js
View file @
8821e0e8
...
@@ -2,7 +2,8 @@ import {
...
@@ -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', () => {
...
@@ -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', () => {
...
@@ -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
);
});
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment