fix(history): respect export permission boundary

This commit is contained in:
lingniu
2026-07-16 08:13:36 +08:00
parent 6049d8c22b
commit 473c9e1251
2 changed files with 24 additions and 2 deletions

View File

@@ -13,11 +13,14 @@ const mocks = vi.hoisted(() => ({
historyExports: vi.fn(),
createHistoryExport: vi.fn()
}));
const auth = vi.hoisted(() => ({ role: 'admin' }));
vi.mock('../../api/client', () => ({ api: mocks }));
vi.mock('../auth/AuthGate', () => ({ usePlatformSession: () => ({ session: { role: auth.role } }) }));
afterEach(() => {
cleanup();
auth.role = 'admin';
Object.values(mocks).forEach((mock) => mock.mockReset());
});
@@ -121,3 +124,18 @@ test('opens a working column visibility panel and preserves non-hideable identit
fireEvent.click(screen.getByRole('button', { name: '关闭列显示设置' }));
expect(screen.queryByRole('dialog', { name: '列显示设置' })).not.toBeInTheDocument();
});
test('keeps history readable without mounting operator-only export requests for a viewer', async () => {
auth.role = 'viewer';
mocks.historyMetricCatalog.mockResolvedValue({ categories: [{ key: 'location', label: '位置数据' }], metrics: [metric] });
mocks.historyData.mockResolvedValue(historyData('OLDVIN', '旧车牌', 'old-as-of'));
mocks.historySeries.mockResolvedValue(historySeries('OLDVIN', '旧车牌', 'old-as-of'));
renderPage();
expect((await screen.findAllByText('旧车牌')).length).toBeGreaterThan(0);
expect(screen.getByText('只读 · 导出需操作员权限')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: /创建导出/ })).not.toBeInTheDocument();
expect(screen.queryByText('导出任务')).not.toBeInTheDocument();
expect(mocks.historyExports).not.toHaveBeenCalled();
expect(mocks.createHistoryExport).not.toHaveBeenCalled();
});