refactor(web): isAdmin 收口到 isAdminProfile(B4)
5 处逐字硬编码 profile?.account==='admin'||userId==='ADMIN'(Topbar/ModelerPage/NewFeatureShell/AiFeatureForm/DesignCenterPage)收口到 auth/token.ts 纯函数 isAdminProfile,口径不变。
顺带:5 个页面测试的 vi.mock('../auth/token') 从整模块替换改为 importOriginal 只覆盖 getProfile(不再 mock 纯函数,修复 mock 漏 isAdminProfile 致的 render 崩)。
验证:新增 token.test.ts 4 测试 + tsc -b 干净 + vitest 18 文件/77 测试全绿。见总览 §10 B4。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
// 红线:发布恒人审;standard 写入恒走后端 PageSchemaWriter(前端只调 /api/design/recipe/compile)。
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { getProfile } from '../auth/token';
|
||||
import { getProfile, isAdminProfile } from '../auth/token';
|
||||
import { AmisRenderer } from '../components/AmisRenderer';
|
||||
|
||||
const TYPE_OPTIONS = [
|
||||
@@ -279,7 +279,7 @@ function RecipeChooser({ onPick }: { onPick: (recipe: string) => void }) {
|
||||
export function NewFeatureShell() {
|
||||
const navigate = useNavigate();
|
||||
const profile = getProfile();
|
||||
const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN';
|
||||
const isAdmin = isAdminProfile(profile);
|
||||
const [recipe, setRecipe] = useState<string | null>(null);
|
||||
const schema = useMemo(() => (recipe ? buildWizardSchema(recipe) : null), [recipe]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user