feat(admin): success flash支持可选链接并用于BAS批次复盘入口
This commit is contained in:
@@ -1635,7 +1635,10 @@ class PlatformOrderController extends Controller
|
||||
(string) $runId,
|
||||
);
|
||||
|
||||
return redirect()->back()->with('success', '批量同步订阅任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ',run_id=' . $runId . ')。');
|
||||
return redirect()->back()
|
||||
->with('success', '批量同步订阅任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ',run_id=' . $runId . ')。')
|
||||
->with('success_link_href', '/admin/platform-batches/show?type=bas&run_id=' . urlencode((string) $runId))
|
||||
->with('success_link_label', '进入批次复盘');
|
||||
}
|
||||
|
||||
public function batchMarkPaidAndActivate(Request $request, SubscriptionActivationService $service): RedirectResponse
|
||||
|
||||
@@ -77,7 +77,18 @@
|
||||
|
||||
{{-- 页面标题已统一收敛到各页面的 PageHeader 组件,避免重复出现“大标题”。 --}}
|
||||
@if(session('success'))
|
||||
<div class="flash" data-flash="success">{{ session('success') }}</div>
|
||||
<div class="flash" data-flash="success">
|
||||
<span>{{ session('success') }}</span>
|
||||
@if(session('success_link_href'))
|
||||
@php
|
||||
$flashLinkHref = \App\Support\BackUrl::sanitizeForLinks((string) session('success_link_href'));
|
||||
$flashLinkLabel = (string) (session('success_link_label') ?: '查看');
|
||||
@endphp
|
||||
@if($flashLinkHref !== '')
|
||||
<a href="{{ $flashLinkHref }}" class="btn btn-secondary btn-sm" style="margin-left:8px;">{{ $flashLinkLabel }}</a>
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
@if(session('warning'))
|
||||
<div class="warning" data-flash="warning">{{ session('warning') }}</div>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminFlashSuccessShouldSupportOptionalLinkTest 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_flash_success_should_render_optional_link_when_session_keys_present(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$res = $this->withSession([
|
||||
'success' => '操作成功',
|
||||
'success_link_href' => '/admin/platform-batches/show?type=bas&run_id=BAS202603171234560001',
|
||||
'success_link_label' => '进入批次复盘',
|
||||
])->get('/admin');
|
||||
|
||||
$res->assertOk();
|
||||
$res->assertSee('操作成功');
|
||||
$res->assertSee('进入批次复盘');
|
||||
$res->assertSee('/admin/platform-batches/show?type=bas&run_id=BAS202603171234560001', false);
|
||||
}
|
||||
|
||||
public function test_flash_success_link_should_be_sanitized_to_relative_path(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$res = $this->withSession([
|
||||
'success' => 'ok',
|
||||
'success_link_href' => 'https://evil.example.com/x',
|
||||
'success_link_label' => '查看',
|
||||
])->get('/admin');
|
||||
|
||||
$res->assertOk();
|
||||
// 外链应被 sanitize 掉,不应渲染 href
|
||||
$res->assertDontSee('https://evil.example.com/x');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user