Comments: Make admin comment dimming comment-type aware (Trac #35214, Stage 3)#57
Open
adamsilverstein wants to merge 2 commits into
Open
Conversation
`wp_ajax_dim_comment()` fell back to the global `moderate_comments` primitive when a user could not `edit_comment` the target comment, so a moderator of a custom comment type could not approve or unapprove comments of that type from the admin list table. Route the fallback through the per-comment `moderate_comment` meta capability. For comment types using the default capability model this resolves to `moderate_comments` (behavior unchanged); a type with its own capabilities is gated by its own moderation primitive. This is the last per-comment moderation gate in the admin AJAX path. The remaining `moderate_comments` checks in the list table (bulk action availability, the Empty Spam/Trash button) and in XML-RPC `wp.getComments` are collection-level, not per-comment, and intentionally stay global. See #35214.
Drive `wp_ajax_dim_comment()` through the Ajax test harness: a moderator of an independent `review` type can dim its comments, while a global `moderate_comments` moderator without the type's capabilities is denied. The existing administrator and subscriber tests continue to pass, confirming the default model is unchanged. See #35214.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Continues Stage 3 of capability enforcement (follow-up to PR #56) with the admin call-site family.
wp_ajax_dim_comment()(approve/unapprove from the comments list table) gated on:The
moderate_commentsfallback is the global primitive, so a moderator of a custom comment type could not dim comments of that type.What changed
Route the fallback through the per-comment
moderate_commentmeta cap (added in #55):For the default capability model
moderate_commentresolves tomoderate_comments, so built-in types are unchanged. A type with its owncapability_typeis gated by its own moderation primitive.Why this is the last per-comment admin gate
After auditing the admin + XML-RPC surface, this is the only remaining per-comment moderation gate using the bare global primitive:
wp-admin/comment.php,edit-comments.php, and the other AJAX comment handlers already gate onedit_comment, which #55 made type-aware.moderate_commentschecks (get_bulk_actions(), the Empty Spam/Trash button) and XML-RPCwp.getComments(status filter) are collection-level, not a specific comment, somoderate_commentdoesn't apply - they correctly stay global.So with this PR, every per-comment moderation gate in core (REST in #56, admin AJAX here) now flows through the type-aware
map_meta_cap()foundation.Testing
Extends the existing
wpAjaxDimComment.phpAjax tests: areview-type moderator (moderate_reviews) can dim a review comment; a globalmoderate_commentsmoderator without the type's caps is denied (-1). The existing administrator and subscriber tests still pass, confirming the default model is unchanged.Full
--group ajax --group comment --group capabilitiespasses (806 tests). PHPCS + PHPStan clean.Stacking
Based on
feature/comment-type-moderation-rest(#56). Retarget totrunkas the stack lands behind #12311.See #35214.