From 8063b8ae9d62e874126b5d329f4ac8f20a0d7bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Mon, 16 Mar 2026 23:00:27 +0800 Subject: [PATCH] chore(governance): block batch activate when syncable_only conflicts with synced_only --- .../Admin/PlatformOrderController.php | 7 +++- app/Support/PlatformOrderToolsGuard.php | 3 ++ ...yncableOnlyConflictsWithSyncedOnlyTest.php | 36 ++++++++++++++++++ ...sableWhenSyncableOnlyAndSyncedOnlyTest.php | 38 +++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenSyncableOnlyConflictsWithSyncedOnlyTest.php create mode 100644 tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenSyncableOnlyAndSyncedOnlyTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 93b89d1..816e8f4 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1424,14 +1424,17 @@ class PlatformOrderController extends Controller return redirect()->back()->with('warning', '为避免误操作,请先在筛选条件中勾选「只看可同步」,再执行批量同步订阅。'); } - // 防误操作(口径一致):当已勾选 syncable_only=1 时,不允许叠加互斥的“同步状态/失败原因”筛选 - // 说明:syncable_only=1 的语义已统一为 unsynced(未同步且非失败)。若仍保留 sync_status=failed/synced 或失败原因关键词, + // 防误操作(口径一致):当已勾选 syncable_only=1 时,不允许叠加互斥的“同步状态/失败原因/已同步”筛选 + // 说明:syncable_only=1 的语义已统一为 unsynced(未同步且非失败)。若仍保留 sync_status=failed/synced、synced_only=1 或失败原因关键词, // 会导致集合为空或语义混乱;这里直接 warning 阻断,避免运营误解。 if ($scope === 'filtered' && ($filters['syncable_only'] ?? '') === '1') { $syncStatus = (string) ($filters['sync_status'] ?? ''); if ($syncStatus !== '' && $syncStatus !== 'unsynced') { return redirect()->back()->with('warning', '当前已勾选「只看可同步」,但同步状态筛选不是「未同步」。请先切回 sync_status=unsynced(或清空同步状态筛选)后再执行批量同步。'); } + if ((string) ($filters['synced_only'] ?? '') === '1') { + return redirect()->back()->with('warning', '当前已勾选「只看可同步」,但又勾选了「只看已同步」:两者语义互斥。请先取消只看已同步后再执行批量同步。'); + } if ((string) ($filters['fail_only'] ?? '') === '1' || trim((string) ($filters['sync_error_keyword'] ?? '')) !== '') { return redirect()->back()->with('warning', '当前筛选包含「同步失败/失败原因」。请先治理失败原因或切回未同步集合,再执行批量同步。'); } diff --git a/app/Support/PlatformOrderToolsGuard.php b/app/Support/PlatformOrderToolsGuard.php index 0c6b932..5bf05ff 100644 --- a/app/Support/PlatformOrderToolsGuard.php +++ b/app/Support/PlatformOrderToolsGuard.php @@ -59,6 +59,9 @@ class PlatformOrderToolsGuard if ($syncStatus !== '' && $syncStatus !== 'unsynced') { return '当前已勾选「只看可同步」,但同步状态筛选不是「未同步」。请先切回 sync_status=unsynced(或清空同步状态筛选)后再批量同步。'; } + if ((string) ($filters['synced_only'] ?? '') === '1') { + return '当前已勾选「只看可同步」,但又勾选了「只看已同步」:两者语义互斥。请先取消只看已同步后再批量同步。'; + } if ((string) ($filters['fail_only'] ?? '') === '1' || trim((string) ($filters['sync_error_keyword'] ?? '')) !== '') { return '当前筛选包含「同步失败/失败原因」。请先治理失败原因或切回未同步集合,再批量同步。'; } diff --git a/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenSyncableOnlyConflictsWithSyncedOnlyTest.php b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenSyncableOnlyConflictsWithSyncedOnlyTest.php new file mode 100644 index 0000000..427085a --- /dev/null +++ b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenSyncableOnlyConflictsWithSyncedOnlyTest.php @@ -0,0 +1,36 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_should_block_when_syncable_only_and_synced_only_present(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->post('/admin/platform-orders/batch-activate-subscriptions', [ + 'scope' => 'filtered', + 'syncable_only' => '1', + 'synced_only' => '1', + 'limit' => 50, + ]); + + $res->assertRedirect(); + $res->assertSessionHas('warning'); + } +} diff --git a/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenSyncableOnlyAndSyncedOnlyTest.php b/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenSyncableOnlyAndSyncedOnlyTest.php new file mode 100644 index 0000000..6042bec --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenSyncableOnlyAndSyncedOnlyTest.php @@ -0,0 +1,38 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_button_should_disable_when_syncable_only_checked_but_synced_only_is_present(): void + { + $this->loginAsPlatformAdmin(); + + // syncable_only=1 语义为“未同步且非失败”,与 synced_only=1(已同步)互斥。 + $res = $this->get('/admin/platform-orders?syncable_only=1&synced_only=1'); + $res->assertOk(); + + $html = (string) $res->getContent(); + + $this->assertStringContainsString('批量同步订阅(当前筛选范围)', $html); + $this->assertStringContainsString('data-role="batch-activate-subscriptions-blocked-hint"', $html); + $this->assertStringContainsString('只看已同步', $html); + + $this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"')); + } +}