Repository navigation
Conversation
[64875] requires edit access to a note's post to update or delete the note, instead of the `moderate_comments` capability, but no test covered it. Add tests that a user who can moderate comments but cannot edit the post gets a 403 when updating or deleting a note, and that the note is unchanged. Both tests fail without the fix. Follow-up to [64875]. See #65819.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: 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:
|
|
Update: resolved — after updating the branch with trunk, all checks pass, so no re-run is needed. The one failing job (PHP 8.3 / MariaDB 11.8 with memcached) fails in |
SainathPoojary
left a comment
There was a problem hiding this comment.
Thanks for adding these tests!
The tests cover the intended permission check and confirm that rejected requests leave the note unchanged. Both tests fail when the note permission check is removed. The full REST comments test class passes in random order on single-site and multisite. LGTM 🚀
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the added note-permission regression tests.
No open issues 🎉
What changed in this PR
Adds regression coverage for the note permission checks introduced in [64875], verifying that comment moderation alone does not allow editing or deleting notes. No production code changes.
Changes:
- Adds a shared fixture creating a note and a moderator without edit access to its post.
- Tests that updating the note returns
rest_cannot_edit(403) and leaves its content unchanged. - Tests that deleting the note returns
rest_cannot_delete(403) and preserves the note.
| File | Description |
|---|---|
| tests/phpunit/tests/rest-api/rest-comments-controller.php | Adds a shared fixture and two note permission regression tests. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
The tests exercise the real REST permission checks and confirm rejected requests preserve the note. Both fail when the note-specific permission check is removed. The affected classes pass three randomized orders on single-site and multisite, and PHPCS passes.
AI review · gpt-6
Verify that `moderate_comments` alone does not allow updating or deleting a note when the user cannot edit its post. Confirm rejected REST requests leave the note unchanged. Developed in: #15187 Props ravipatel, sainathpoojary. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65083 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #15187 landed in https://core.trac.wordpress.org/changeset/65083 |
Verify that `moderate_comments` alone does not allow updating or deleting a note when the user cannot edit its post. Confirm rejected REST requests leave the note unchanged. Developed in: WordPress/wordpress-develop#15187 Props ravipatel, sainathpoojary. See #65819. Built from https://develop.svn.wordpress.org/trunk@65083 git-svn-id: http://core.svn.wordpress.org/trunk@64233 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: https://core.trac.wordpress.org/ticket/65819
Follow-up to [64875].
Summary
[64875] requires edit access to a note's post to update or delete the note, instead of the
moderate_commentscapability, but no test covers that check. This adds two tests toWP_Test_REST_Comments_Controller:rest_cannot_edit(403) when updating the note, and the content is unchanged;rest_cannot_delete(403) when deleting the note, and the note still exists.Both tests fail if the note check added in [64875] is removed (the update and delete then succeed). No source changes.
Related: #15130 adds the equivalent coverage for reactions.
Testing
WP_Test_REST_Comments_Controller: OK (286 tests).phpcs: no issues.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the untested permission check, drafting the tests and this description. I reviewed the tests and confirmed they fail without the fix.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the WordPress Core Handbook for more details.