Skip to content

Commit cf77916

Browse files
committed
fix: scope large-batch dismiss by rule, not just object (PRO-1264)
dismiss_issue()'s largeBatch path selected and updated every row matching only siteid+object, so a global/large-batch dismiss on one rule violation also silently dismissed unrelated rule violations that happened to share the same object. Fetch the representative issue's rule alongside its object and filter the batch query by both, matching the scoping the pro plugin's global-ignore lookup already uses. Also fixes two existing largeBatch tests whose fixtures used different rules per row within a single "batch" object — that setup encoded the same assumption behind the bug, so those rows would no longer be recognized as belonging to the same batch under the corrected query.
1 parent c8b986a commit cf77916

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

includes/classes/class-rest-api.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,11 @@ public function dismiss_issue( $request ) {
12301230
// If largeBatch is set, verify edit permission for all matching rows,
12311231
// then perform a single object-based update.
12321232
if ( $large_batch ) {
1233-
// Get the 'object' from the issue id.
1233+
// Get the 'rule' and 'object' from the issue id so the batch is scoped to both.
12341234
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Need fresh data.
1235-
$object = $wpdb->get_var( $wpdb->prepare( 'SELECT object FROM %i WHERE id = %d', $table_name, $issue_id ) );
1235+
$representative_row = $wpdb->get_row( $wpdb->prepare( 'SELECT rule, object FROM %i WHERE id = %d', $table_name, $issue_id ), ARRAY_A );
1236+
$rule = $representative_row['rule'] ?? '';
1237+
$object = $representative_row['object'] ?? '';
12361238

12371239
if ( ! $object ) {
12381240
return new \WP_Error(
@@ -1247,10 +1249,11 @@ public function dismiss_issue( $request ) {
12471249
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Need current rows for permission validation.
12481250
$issue_rows = $wpdb->get_results(
12491251
$wpdb->prepare(
1250-
'SELECT id, postid FROM %i WHERE siteid = %d AND object = %s',
1252+
'SELECT id, postid FROM %i WHERE siteid = %d AND object = %s AND rule = %s',
12511253
$table_name,
12521254
$site_id,
1253-
$object
1255+
$object,
1256+
$rule
12541257
),
12551258
ARRAY_A
12561259
);

tests/phpunit/includes/classes/RestApiEndpointsTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ public function test_large_batch_dismiss_authorized_on_all() {
692692
$batch_object = 'batch-all-authorized-test-' . wp_generate_uuid4();
693693

694694
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
695-
// Create multiple issues with the same object (batch).
695+
// Create multiple issues sharing the same rule AND object (batch).
696696
$issue_ids = [];
697697
for ( $i = 1; $i <= 3; $i++ ) {
698698
$post_id = ( $i <= 2 ) ? $post_1 : $post_2;
@@ -702,7 +702,7 @@ public function test_large_batch_dismiss_authorized_on_all() {
702702
'postid' => $post_id,
703703
'siteid' => $site_id,
704704
'type' => 'error',
705-
'rule' => 'batch-auth-test-' . $i,
705+
'rule' => 'batch-auth-test',
706706
'ruletype' => 'error',
707707
'object' => $batch_object,
708708
'recordcheck' => 1,
@@ -930,13 +930,14 @@ public function test_large_batch_dismiss_authorized_on_some() {
930930

931931
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
932932
// Create first issue on limited_id's post (limited user CAN edit).
933+
// Both rows share the same rule AND object so they land in the same batch.
933934
$wpdb->insert(
934935
$table_name,
935936
[
936937
'postid' => $limited_post,
937938
'siteid' => $site_id,
938939
'type' => 'error',
939-
'rule' => 'batch-partial-1',
940+
'rule' => 'batch-partial-test',
940941
'ruletype' => 'error',
941942
'object' => $batch_object,
942943
'recordcheck' => 1,
@@ -955,7 +956,7 @@ public function test_large_batch_dismiss_authorized_on_some() {
955956
'postid' => $admin_post,
956957
'siteid' => $site_id,
957958
'type' => 'error',
958-
'rule' => 'batch-partial-2',
959+
'rule' => 'batch-partial-test',
959960
'ruletype' => 'error',
960961
'object' => $batch_object,
961962
'recordcheck' => 1,

0 commit comments

Comments
 (0)