Repository navigation
Notes: Use the note permission check when deleting a reaction - #85883
Conversation
A reaction belongs to a note, and the rest of the comments controller already treats reactions like notes. Deleting one, though, still went through core's check_edit_permission(), which on WordPress 7.0 and 7.1 only knows about notes, so a reaction was checked against the moderate_comments capability instead. Override check_edit_permission() so notes and reactions both use edit_comment, which maps to edit_post on the note's post. Reactions cannot be updated, so this only changes who can delete them. This mirrors a pending WordPress core change. The backport changelog entry will be added once the core pull request exists.
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the ⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. As a user I want to be able to add multiple close buttons so that users can close the overlay from different positions in
|
| 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 ) ) { |
There was a problem hiding this comment.
Minor - could it use is_note_or_reaction?
Also, that method doesn't strtolower the comment_type. Bug, or is the code here over protective?
There was a problem hiding this comment.
Yeah I saw is_note_or_reaction and 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?
strtolower was there for edge cases to a comment type of Note or Reaction. In the database it's case insensitive.
So where, for example, a comment stored as 'Note' is returned by note queries.
| if ( current_user_can( 'moderate_comments' ) ) { | ||
| return true; | ||
| } | ||
|
|
||
| return current_user_can( 'edit_comment', $comment->comment_ID ); |
There was a problem hiding this comment.
I realise this is the existing code, but maybe it could be:
| if ( current_user_can( 'moderate_comments' ) ) { | |
| return true; | |
| } | |
| return current_user_can( 'edit_comment', $comment->comment_ID ); | |
| return current_user_can( 'moderate_comments' ) || current_user_can( 'edit_comment', $comment->comment_ID ); |
talldan
left a comment
There was a problem hiding this comment.
Does what it says it'll do, so LGTM.
A couple of small code nits.
|
I think @adamsilverstein is working on something similar (#85415); it's worth double-checking the permissions. User A shouldn't be able to toggle User B's reactions. |
Ah great. Thanks @Mamaduka Happy to close this and the backport PR - I guess I should have checked, but that would have been too easy. 😄 |
|
#85415 is a bit different than this and is about preventing others from removing your reactions (and removing reactions from resolved threads). We can consider it separately, this PR looks good to me. |
|
Tested this on WordPress 7.2-beta3-64990 with Gutenberg 24.3.0, applying only the Real REST requests (
Matches the core change in WordPress/wordpress-develop#15130, which I tested the same way. |
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org> Co-authored-by: sadmansakibnadvi <sadmansakibnadvi@git.wordpress.org>
|
I just cherry-picked this PR to the wp/7.2 branch to get it included in the next release: 71d0377 |
This updates the pinned commit hash of the Gutenberg repository from `cc75a79186fd23e72eb015d594e82f40c6209eb5` to `c035c1a649ef68f5c1646694cf440df1d7ae6e62` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@cc75a79...c035c1a - Components: Use solid brand highlights for popup items (WordPress/gutenberg#84583) (#85848) - Fix endless sideload loop when the browser can't decode a big image (WordPress/gutenberg#83530) - Notes: Show reaction picker as a row of emoji (WordPress/gutenberg#85819) (#85892) - Notes: Add thumbs up and plus reactions (WordPress/gutenberg#85565) - Notes: Share thread focus recovery across actions (WordPress/gutenberg#85455) - Core Fields: Prevent extra space between `/` and text in slug input (WordPress/gutenberg#85935) - Notes: Add search and a status filter to the All Notes sidebar (WordPress/gutenberg#84060) - Notes: Use the note permission check when deleting a reaction (WordPress/gutenberg#85883) - [WP 7.2] Math block: Keyboard focus is trapped in the LaTeX field when the formula has an error (WordPress/gutenberg#86032) - Core fields: Keep the status icon full size when its label wraps (WordPress/gutenberg#85828) (#86050) - [WP 7.2] ToolsPanel: Keep the "Reset" label visible on the highlighted menu item (WordPress/gutenberg#86060) - Interactivity Router: Ignore router regions and attachTo targets inside data-wp-html content (WordPress/gutenberg#84919) (#86059) - [WP 7.2] wp-build: Derive CSS module class names from each stylesheet's CSS (WordPress/gutenberg#86062) - Playlist: Allow track without an attachment ID to render on the frontend (WordPress/gutenberg#83880) (#86158) - UI: Show only the day number in Calendar day cells (WordPress/gutenberg#86010) (#86183) - Notes: Tolerate a null comment in the reaction cascade hooks (WordPress/gutenberg#85959) - Rich Text: Remove stale format boundary when field loses selection (WordPress/gutenberg#86168) - Notes: Only let a reaction's author delete it (WordPress/gutenberg#85415) - Writing flow: Fix Arrow Up and Down getting stuck at the edge of the screen (WordPress/gutenberg#85408) - Try: Run e2e tests in parallel, on one wp-env site per two cores (WordPress/gutenberg#85420) - Raw handling: Keep shortcodes in text inline (WordPress/gutenberg#85795) - Fix: Fixes non-breaking space replacement tooltip (WordPress/gutenberg#85777) - Non-breaking space: Remove non-breaking spaces that would collapse when replaced (WordPress/gutenberg#85873) Props mamaduka. See #66340. git-svn-id: https://develop.svn.wordpress.org/trunk@65225 602fd350-edb4-49c9-b593-d223f7449a82
This updates the pinned commit hash of the Gutenberg repository from `cc75a79186fd23e72eb015d594e82f40c6209eb5` to `c035c1a649ef68f5c1646694cf440df1d7ae6e62` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@cc75a79...c035c1a - Components: Use solid brand highlights for popup items (WordPress/gutenberg#84583) (#85848) - Fix endless sideload loop when the browser can't decode a big image (WordPress/gutenberg#83530) - Notes: Show reaction picker as a row of emoji (WordPress/gutenberg#85819) (#85892) - Notes: Add thumbs up and plus reactions (WordPress/gutenberg#85565) - Notes: Share thread focus recovery across actions (WordPress/gutenberg#85455) - Core Fields: Prevent extra space between `/` and text in slug input (WordPress/gutenberg#85935) - Notes: Add search and a status filter to the All Notes sidebar (WordPress/gutenberg#84060) - Notes: Use the note permission check when deleting a reaction (WordPress/gutenberg#85883) - [WP 7.2] Math block: Keyboard focus is trapped in the LaTeX field when the formula has an error (WordPress/gutenberg#86032) - Core fields: Keep the status icon full size when its label wraps (WordPress/gutenberg#85828) (#86050) - [WP 7.2] ToolsPanel: Keep the "Reset" label visible on the highlighted menu item (WordPress/gutenberg#86060) - Interactivity Router: Ignore router regions and attachTo targets inside data-wp-html content (WordPress/gutenberg#84919) (#86059) - [WP 7.2] wp-build: Derive CSS module class names from each stylesheet's CSS (WordPress/gutenberg#86062) - Playlist: Allow track without an attachment ID to render on the frontend (WordPress/gutenberg#83880) (#86158) - UI: Show only the day number in Calendar day cells (WordPress/gutenberg#86010) (#86183) - Notes: Tolerate a null comment in the reaction cascade hooks (WordPress/gutenberg#85959) - Rich Text: Remove stale format boundary when field loses selection (WordPress/gutenberg#86168) - Notes: Only let a reaction's author delete it (WordPress/gutenberg#85415) - Writing flow: Fix Arrow Up and Down getting stuck at the edge of the screen (WordPress/gutenberg#85408) - Try: Run e2e tests in parallel, on one wp-env site per two cores (WordPress/gutenberg#85420) - Raw handling: Keep shortcodes in text inline (WordPress/gutenberg#85795) - Fix: Fixes non-breaking space replacement tooltip (WordPress/gutenberg#85777) - Non-breaking space: Remove non-breaking spaces that would collapse when replaced (WordPress/gutenberg#85873) Props mamaduka. See #66340. Built from https://develop.svn.wordpress.org/trunk@65225 git-svn-id: http://core.svn.wordpress.org/trunk@64374 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This updates the pinned commit hash of the Gutenberg repository from `cc75a79186fd23e72eb015d594e82f40c6209eb5` to `c035c1a649ef68f5c1646694cf440df1d7ae6e62` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@cc75a79...c035c1a - Components: Use solid brand highlights for popup items (WordPress/gutenberg#84583) (#85848) - Fix endless sideload loop when the browser can't decode a big image (WordPress/gutenberg#83530) - Notes: Show reaction picker as a row of emoji (WordPress/gutenberg#85819) (#85892) - Notes: Add thumbs up and plus reactions (WordPress/gutenberg#85565) - Notes: Share thread focus recovery across actions (WordPress/gutenberg#85455) - Core Fields: Prevent extra space between `/` and text in slug input (WordPress/gutenberg#85935) - Notes: Add search and a status filter to the All Notes sidebar (WordPress/gutenberg#84060) - Notes: Use the note permission check when deleting a reaction (WordPress/gutenberg#85883) - [WP 7.2] Math block: Keyboard focus is trapped in the LaTeX field when the formula has an error (WordPress/gutenberg#86032) - Core fields: Keep the status icon full size when its label wraps (WordPress/gutenberg#85828) (#86050) - [WP 7.2] ToolsPanel: Keep the "Reset" label visible on the highlighted menu item (WordPress/gutenberg#86060) - Interactivity Router: Ignore router regions and attachTo targets inside data-wp-html content (WordPress/gutenberg#84919) (#86059) - [WP 7.2] wp-build: Derive CSS module class names from each stylesheet's CSS (WordPress/gutenberg#86062) - Playlist: Allow track without an attachment ID to render on the frontend (WordPress/gutenberg#83880) (#86158) - UI: Show only the day number in Calendar day cells (WordPress/gutenberg#86010) (#86183) - Notes: Tolerate a null comment in the reaction cascade hooks (WordPress/gutenberg#85959) - Rich Text: Remove stale format boundary when field loses selection (WordPress/gutenberg#86168) - Notes: Only let a reaction's author delete it (WordPress/gutenberg#85415) - Writing flow: Fix Arrow Up and Down getting stuck at the edge of the screen (WordPress/gutenberg#85408) - Try: Run e2e tests in parallel, on one wp-env site per two cores (WordPress/gutenberg#85420) - Raw handling: Keep shortcodes in text inline (WordPress/gutenberg#85795) - Fix: Fixes non-breaking space replacement tooltip (WordPress/gutenberg#85777) - Non-breaking space: Remove non-breaking spaces that would collapse when replaced (WordPress/gutenberg#85873) Props mamaduka. See #66340. git-svn-id: https://develop.svn.wordpress.org/trunk@65225 602fd350-edb4-49c9-b593-d223f7449a82
What?
Deleting a note reaction now needs the same permission as deleting the note: edit access to the note's post.
Why?
The comments controller already treats a reaction like its note when reading or creating one. Deleting was the exception. It went through core's
check_edit_permission(), which only knows about notes, so a reaction was checked against themoderate_commentscapability instead.How?
check_edit_permission()inGutenberg_REST_Comment_Controller_7_2. It's core's method withreactionchecked alongsidenote: both useedit_comment, which maps toedit_poston the note's post. Other comment types still checkmoderate_commentsfirst.moderate_commentsbut can't edit posts.Testing Instructions
<id>with the reaction's ID:403and the command in step 3 still lists the reaction. On trunk it prints200and the reaction is gone.