Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2437,10 +2437,10 @@ protected function check_edit_permission( $comment ) {
}

/*
* Notes are editorial content, so require edit access to the note's post
* rather than the moderate_comments capability.
* Notes and their reactions are editorial content, so require edit access
* to the note's post rather than the moderate_comments capability.
*/
if ( 'note' === strtolower( $comment->comment_type ) ) {
if ( in_array( strtolower( $comment->comment_type ), array( 'note', 'reaction' ), true ) ) {
return current_user_can( 'edit_comment', $comment->comment_ID );
}

Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/tests/rest-api/rest-comments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5860,6 +5860,44 @@ public function test_delete_reaction_requires_edit_permission() {
$this->assertNotNull( get_comment( $reaction_id ) );
}

/**
* A user with moderate_comments but no editing capabilities cannot remove a
* reaction on a post they cannot edit.
*
* @ticket 66406
*/
public function test_moderator_cannot_delete_reaction() {
$post_id = self::factory()->post->create( array( 'post_author' => self::$editor_id ) );
$note_id = self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_type' => 'note',
'comment_approved' => 0,
'user_id' => self::$editor_id,
'comment_content' => 'Test note',
)
);
$reaction_id = self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_type' => 'reaction',
'comment_parent' => $note_id,
'comment_approved' => 1,
'user_id' => self::$editor_id,
'comment_content' => '2764',
)
);

wp_set_current_user( self::$moderator_id );

$request = new WP_REST_Request( 'DELETE', '/wp/v2/comments/' . $reaction_id );
$request->set_param( 'force', true );
$response = rest_get_server()->dispatch( $request );

$this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
$this->assertNotNull( get_comment( $reaction_id ), 'Reaction must still exist.' );
}

/**
* A reaction's author can remove it from a note somebody else wrote.
*
Expand Down
Loading