修正项目访问与角色排序体验

- 登录成功后按用户恢复上次项目,管理员优先选择启用项目\n- 项目详情路由增加 setup_config:read 权限校验,未授权时回到可访问页面\n- 项目管理操作按当前项目行角色读取权限,避免误用首个角色权限\n- 角色模板排序中固定 PM 优先,保持角色列表、生效管理和权限编辑器顺序一致\n- 补充登录、路由、项目管理和角色排序相关测试
This commit is contained in:
Cheng Zhou
2026-06-04 16:31:56 +08:00
parent 0b3a4d4d31
commit e78bb04c4b
8 changed files with 60 additions and 17 deletions
@@ -6,11 +6,11 @@ import { useRoleTemplateMeta } from "./useRoleTemplateMeta";
vi.mock("@/api/projectPermissions", () => ({
fetchPermissionTemplates: vi.fn().mockResolvedValue({
data: [
{ category: "PM", name: "PM" },
{ category: "CRA", name: "CRA" },
{ category: "CTA", name: "CTA" },
{ category: "QA", name: "QA" },
{ category: "PV", name: "PV" },
{ category: "QA", name: "QA" },
{ category: "CTA", name: "CTA" },
{ category: "CRA", name: "CRA" },
{ category: "PM", name: "PM" },
],
}),
}));
@@ -31,16 +31,16 @@ describe("useRoleTemplateMeta fallback copy", () => {
expect(source).toContain("负责药物警戒相关工作,跟踪安全性事件并支持风险评估。");
});
it("sorts roles by the role template list order", async () => {
it("pins PM first before applying the role template list order", async () => {
const { compareRolesByTemplateOrder, loadRoleTemplates } = useRoleTemplateMeta();
await loadRoleTemplates();
expect(["CRA", "PV", "QA", "PM", "CTA"].sort(compareRolesByTemplateOrder)).toEqual([
"PM",
"CRA",
"CTA",
"QA",
"PV",
"QA",
"CTA",
"CRA",
]);
});
});
@@ -1,5 +1,6 @@
import { computed, ref } from "vue";
import { fetchPermissionTemplates, type PermissionTemplate } from "@/api/projectPermissions";
import { compareProjectPermissionRoles } from "@/utils/projectPermissionRoles";
const FALLBACK_ROLE_META: Record<string, { label: string; icon: string; desc: string }> = {
ADMIN: { label: "管理员", icon: "🛡️", desc: "系统管理员" },
@@ -58,6 +59,7 @@ export const useRoleTemplateMeta = () => {
});
const compareRolesByTemplateOrder = (a: string, b: string) => {
if (a === "PM" || b === "PM") return compareProjectPermissionRoles(a, b);
const order = roleOrder.value;
const aOrder = order[a] ?? Number.MAX_SAFE_INTEGER;
const bOrder = order[b] ?? Number.MAX_SAFE_INTEGER;