forked from longtao.wu/droboticflow
🛡️ Redirect supplier managers to scoped dashboard
This commit is contained in:
parent
ef778b4287
commit
0a0769ff23
83
src/App.tsx
83
src/App.tsx
@ -4,10 +4,10 @@
|
||||
*/
|
||||
|
||||
import React, { Suspense, lazy } from "react";
|
||||
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
|
||||
import { BrowserRouter as Router, Navigate, Routes, Route, useLocation } from "react-router-dom";
|
||||
import { Layout } from "./components/Layout";
|
||||
import { TimeZoneProvider } from "./context/TimeZoneContext";
|
||||
import { UserProvider } from "./context/UserContext";
|
||||
import { UserProvider, useUser } from "./context/UserContext";
|
||||
|
||||
type LazyRouteModule = { default: React.ComponentType };
|
||||
|
||||
@ -98,6 +98,15 @@ function RouteFallback() {
|
||||
return <div className="flex min-h-[320px] items-center justify-center text-sm text-slate-400">正在加载页面...</div>;
|
||||
}
|
||||
|
||||
function RoleRouteGuard({ children }: { children: React.ReactNode }) {
|
||||
const { currentUser } = useUser();
|
||||
const location = useLocation();
|
||||
if (currentUser?.role === "supplier_manager" && location.pathname !== "/") {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<UserProvider>
|
||||
@ -106,40 +115,42 @@ export default function App() {
|
||||
<Layout>
|
||||
<RouteErrorBoundary>
|
||||
<Suspense fallback={<RouteFallback />}>
|
||||
<Routes>
|
||||
<Route path="/" element={<Dashboard />} />
|
||||
<Route path="/projects" element={<Projects />} />
|
||||
<Route path="/project/:id" element={<ProjectDetail />} />
|
||||
<Route path="/operators" element={<Operators />} />
|
||||
<Route path="/workflow/:id" element={<WorkflowEditor />} />
|
||||
<Route path="/data-assets" element={<DataAssets />} />
|
||||
<Route path="/data-operations" element={<DataOperations />} />
|
||||
<Route path="/database" element={<DatabaseBrowser />} />
|
||||
<Route path="/object-storage" element={<ObjectStorageBrowser />} />
|
||||
<Route path="/object-sync" element={<ObjectSync />} />
|
||||
<Route path="/source-data" element={<LegacyDataAssetsRedirect />} />
|
||||
<Route path="/packages" element={<LegacyDataAssetsRedirect />} />
|
||||
<Route path="/sampling" element={<Sampling />} />
|
||||
<Route path="/annotation-operations" element={<AnnotationOperations />} />
|
||||
<Route
|
||||
path="/plugins/annotation-qa/workflows/:workflowId/annotate"
|
||||
element={<AnnotationOperations />}
|
||||
/>
|
||||
<Route
|
||||
path="/plugins/annotation-qa/workflows/:workflowId/quality"
|
||||
element={<AnnotationOperations />}
|
||||
/>
|
||||
<Route
|
||||
path="/plugins/annotation-qa/workflows/:workflowId/acceptance"
|
||||
element={<AnnotationOperations />}
|
||||
/>
|
||||
<Route path="/plugins/annotation-qa/items/:itemId" element={<AnnotationOperations />} />
|
||||
<Route path="/monitoring" element={<Monitoring />} />
|
||||
<Route path="/audit" element={<Audit />} />
|
||||
<Route path="/settings" element={<Settings />} />
|
||||
<Route path="/templates" element={<Templates />} />
|
||||
<Route path="/users" element={<Users />} />
|
||||
</Routes>
|
||||
<RoleRouteGuard>
|
||||
<Routes>
|
||||
<Route path="/" element={<Dashboard />} />
|
||||
<Route path="/projects" element={<Projects />} />
|
||||
<Route path="/project/:id" element={<ProjectDetail />} />
|
||||
<Route path="/operators" element={<Operators />} />
|
||||
<Route path="/workflow/:id" element={<WorkflowEditor />} />
|
||||
<Route path="/data-assets" element={<DataAssets />} />
|
||||
<Route path="/data-operations" element={<DataOperations />} />
|
||||
<Route path="/database" element={<DatabaseBrowser />} />
|
||||
<Route path="/object-storage" element={<ObjectStorageBrowser />} />
|
||||
<Route path="/object-sync" element={<ObjectSync />} />
|
||||
<Route path="/source-data" element={<LegacyDataAssetsRedirect />} />
|
||||
<Route path="/packages" element={<LegacyDataAssetsRedirect />} />
|
||||
<Route path="/sampling" element={<Sampling />} />
|
||||
<Route path="/annotation-operations" element={<AnnotationOperations />} />
|
||||
<Route
|
||||
path="/plugins/annotation-qa/workflows/:workflowId/annotate"
|
||||
element={<AnnotationOperations />}
|
||||
/>
|
||||
<Route
|
||||
path="/plugins/annotation-qa/workflows/:workflowId/quality"
|
||||
element={<AnnotationOperations />}
|
||||
/>
|
||||
<Route
|
||||
path="/plugins/annotation-qa/workflows/:workflowId/acceptance"
|
||||
element={<AnnotationOperations />}
|
||||
/>
|
||||
<Route path="/plugins/annotation-qa/items/:itemId" element={<AnnotationOperations />} />
|
||||
<Route path="/monitoring" element={<Monitoring />} />
|
||||
<Route path="/audit" element={<Audit />} />
|
||||
<Route path="/settings" element={<Settings />} />
|
||||
<Route path="/templates" element={<Templates />} />
|
||||
<Route path="/users" element={<Users />} />
|
||||
</Routes>
|
||||
</RoleRouteGuard>
|
||||
</Suspense>
|
||||
</RouteErrorBoundary>
|
||||
</Layout>
|
||||
|
||||
@ -6,6 +6,7 @@ const annotationURL = new URL("../../src/pages/AnnotationOperations.tsx", import
|
||||
const dashboardURL = new URL("../../src/pages/Dashboard.tsx", import.meta.url);
|
||||
const sidebarURL = new URL("../../src/components/Sidebar.tsx", import.meta.url);
|
||||
const workflowEditorURL = new URL("../../src/pages/WorkflowEditor.tsx", import.meta.url);
|
||||
const appURL = new URL("../../src/App.tsx", import.meta.url);
|
||||
|
||||
test("human work uses claim and release pools without manual assignment", async () => {
|
||||
const source = await readFile(annotationURL, "utf8");
|
||||
@ -36,3 +37,9 @@ test("workflow run input renders a per-run Handpose switch", async () => {
|
||||
assert.match(source, /包含 Handpose 交付/);
|
||||
assert.match(source, /includeHandpose: event\.target\.checked/);
|
||||
});
|
||||
|
||||
test("supplier managers are redirected away from non-dashboard deep links", async () => {
|
||||
const source = await readFile(appURL, "utf8");
|
||||
assert.match(source, /currentUser\?\.role === "supplier_manager"/);
|
||||
assert.match(source, /<Navigate to="\/" replace/);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user