forked from wangziqi/gongxue-base
- H4: scoped SSE import progress to exact userId match; non-HTTP events excluded from all subscribers - H2: moved PRAGMA foreign_key_check inside SQLite transaction before COMMIT; violations rollback preserving old tables - M1: removed dead axios-style error branch from extractErrorMessage (interceptor already unwraps) - M2: split handleSave try/catch — save errors vs reload errors shown distinctly - M3: added provider field validation before AI config test request - Added SSE scoping regression tests (import service + controller) - Added FK check failure rollback test (database-migrations.spec) - Updated controller spec expectations for userId parameter Co-authored-by: Code Review <branch-review>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import React from 'react';
|
|
import { Result, Button } from 'antd';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { findRoleAwareLandingPath } from '../auth/menu-policy';
|
|
import { usePermission } from '../hooks/usePermission';
|
|
|
|
interface PermissionRouteProps {
|
|
permission: string;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
const PermissionRoute: React.FC<PermissionRouteProps> = ({ permission, children }) => {
|
|
const { permissions, hasPermission } = usePermission();
|
|
const navigate = useNavigate();
|
|
if (!hasPermission(permission)) {
|
|
let roles: string[] = [];
|
|
try {
|
|
roles = JSON.parse(localStorage.getItem('user') || '{}').roles || [];
|
|
} catch {
|
|
roles = [];
|
|
}
|
|
const firstPath = findRoleAwareLandingPath(roles, permissions);
|
|
return (
|
|
<Result
|
|
status="403"
|
|
title="无权访问"
|
|
subTitle="您没有访问此页面的权限"
|
|
extra={firstPath ? <Button type="primary" onClick={() => navigate(firstPath, { replace: true })}>前往可访问页面</Button> : undefined}
|
|
/>
|
|
);
|
|
}
|
|
return <>{children}</>;
|
|
};
|
|
|
|
export default PermissionRoute;
|