Repository navigation
Notes: Use the note permission check when deleting a reaction #85883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/15130 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/85883 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -354,6 +354,39 @@ public function update_item_permissions_check( $request ) { | |||||||||||||
| return parent::update_item_permissions_check( $request ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Checks if a comment can be edited or deleted. | ||||||||||||||
| * | ||||||||||||||
| * Copied from core, extended to the 'reaction' type. A reaction requires | ||||||||||||||
| * the same edit access to the note's post as the note it belongs to. | ||||||||||||||
| * | ||||||||||||||
| * @since 7.2.0 | ||||||||||||||
| * | ||||||||||||||
| * @param WP_Comment $comment Comment object. | ||||||||||||||
| * @return bool Whether the comment can be edited or deleted. | ||||||||||||||
| */ | ||||||||||||||
| protected function check_edit_permission( $comment ) { | ||||||||||||||
| if ( 0 === (int) get_current_user_id() ) { | ||||||||||||||
| return false; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // START CHANGE: Check notes and reactions against the note's post. | ||||||||||||||
| /* | ||||||||||||||
| * Notes and their reactions are editorial content, so require edit access | ||||||||||||||
| * to the note's post rather than the moderate_comments capability. | ||||||||||||||
| */ | ||||||||||||||
| if ( in_array( strtolower( $comment->comment_type ), array( 'note', 'reaction' ), true ) ) { | ||||||||||||||
| return current_user_can( 'edit_comment', $comment->comment_ID ); | ||||||||||||||
| } | ||||||||||||||
| // END CHANGE. | ||||||||||||||
|
|
||||||||||||||
| if ( current_user_can( 'moderate_comments' ) ) { | ||||||||||||||
| return true; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return current_user_can( 'edit_comment', $comment->comment_ID ); | ||||||||||||||
|
Comment on lines
+383
to
+387
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realise this is the existing code, but maybe it could be:
Suggested change
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Checks if a given request has access to create a comment. | ||||||||||||||
| * | ||||||||||||||
|
|
||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor - could it use
is_note_or_reaction?Also, that method doesn't
strtolowerthecomment_type. Bug, or is the code here over protective?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I saw
is_note_or_reactionand noticed it was a Gutenberg only helper. Not sure what the reasoning behind that was.We could use it, but I think matching Core might be less confusing in the end. I'm on the fence. Maybe @adamsilverstein has a preference?
strtolowerwas there for edge cases to a comment type ofNoteorReaction. In the database it's case insensitive.So where, for example, a comment stored as 'Note' is returned by note queries.