Governance: block clear sync errors when synced_only present

This commit is contained in:
萝卜
2026-03-17 00:13:19 +08:00
parent c0e3dffce1
commit 0e8a9797b9
4 changed files with 101 additions and 0 deletions

View File

@@ -2131,6 +2131,9 @@ class PlatformOrderController extends Controller
if ((string) ($filters['syncable_only'] ?? '') === '1') { if ((string) ($filters['syncable_only'] ?? '') === '1') {
return redirect()->back()->with('warning', '当前已勾选「只看可同步」:该集合与「同步失败」互斥,请先取消只看可同步或切到失败集合后再清理。'); return redirect()->back()->with('warning', '当前已勾选「只看可同步」:该集合与「同步失败」互斥,请先取消只看可同步或切到失败集合后再清理。');
} }
if ((string) ($filters['synced_only'] ?? '') === '1') {
return redirect()->back()->with('warning', '当前已勾选「只看已同步」:该集合与「同步失败」治理集合无关,请先取消只看已同步或切到失败集合后再清理。');
}
} }
$query = PlatformOrder::query() $query = PlatformOrder::query()

View File

@@ -167,6 +167,10 @@ class PlatformOrderToolsGuard
return '当前已勾选「只看可同步」:该集合与「同步失败」互斥,请先取消只看可同步或切到失败集合后再清理。'; return '当前已勾选「只看可同步」:该集合与「同步失败」互斥,请先取消只看可同步或切到失败集合后再清理。';
} }
if ((string) ($filters['synced_only'] ?? '') === '1') {
return '当前已勾选「只看已同步」:该集合与「同步失败」治理集合无关,请先取消只看已同步或切到失败集合后再清理。';
}
$hasAnyFailedScope = ($syncStatus === 'failed') $hasAnyFailedScope = ($syncStatus === 'failed')
|| ((string) ($filters['fail_only'] ?? '') === '1') || ((string) ($filters['fail_only'] ?? '') === '1')
|| (trim((string) ($filters['sync_error_keyword'] ?? '')) !== ''); || (trim((string) ($filters['sync_error_keyword'] ?? '')) !== '');

View File

@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderClearSyncErrorsShouldBlockWhenSyncedOnlyTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_clear_sync_errors_filtered_should_block_when_synced_only_is_set(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'clear_sync_err_conflict_synced_only_plan',
'name' => '清理同步失败标记冲突synced_only测试套餐',
'billing_cycle' => 'monthly',
'price' => 1,
'list_price' => 1,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_CLEAR_SYNC_CONFLICT_SYNCED_ONLY_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 1,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [
'subscription_activation_error' => [
'message' => '模拟失败',
'at' => now()->toDateTimeString(),
'admin_id' => 1,
],
'subscription_activation' => [
'subscription_id' => 999,
],
],
]);
$this->post('/admin/platform-orders/clear-sync-errors', [
'scope' => 'filtered',
'synced_only' => '1',
'sync_status' => 'failed',
])
->assertRedirect()
->assertSessionHas('warning');
$order->refresh();
$this->assertNotEmpty(data_get($order->meta, 'subscription_activation_error.message'));
}
}

View File

@@ -58,6 +58,22 @@ class AdminPlatformOrderIndexClearErrorButtonsShouldDisableWhenNotInFailedScopeT
$this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"')); $this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"'));
} }
public function test_clear_sync_errors_button_should_disable_when_synced_only_checked_even_if_in_failed_scope(): void
{
$this->loginAsPlatformAdmin();
$res = $this->get('/admin/platform-orders?sync_status=failed&synced_only=1');
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString('清除同步失败标记(当前筛选范围)', $html);
$this->assertStringContainsString('data-role="clear-sync-errors-blocked-hint"', $html);
$this->assertStringContainsString('只看已同步', $html);
$this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"'));
}
public function test_clear_bmpa_errors_button_should_disable_when_syncable_only_checked_even_if_in_bmpa_failed_scope(): void public function test_clear_bmpa_errors_button_should_disable_when_syncable_only_checked_even_if_in_bmpa_failed_scope(): void
{ {
$this->loginAsPlatformAdmin(); $this->loginAsPlatformAdmin();