权限管理:接入项目级权限矩阵
新增项目级角色权限矩阵,覆盖 PM、CRA、PV、IMP、QA 等项目角色,并通过迁移表持久化各业务模块的读写权限。 后端将参与者、合同费用、物资、启动、里程碑、风险问题、监查稽查、FAQ、共享库、文件版本等接口接入矩阵校验,修复审计日志导出权限和登录 502 的依赖导入问题。 前端新增权限管理页面和项目路由权限映射,按矩阵控制导航显示、直接访问拦截、操作按钮启停,并限制管理后台仅 admin 和授权 PM 可进入。 补充后端权限归一化与接口静态测试、前端路由/权限工具/权限管理页面/工作台等回归测试。
This commit is contained in:
@@ -5,19 +5,19 @@ import { TEXT } from "../locales";
|
||||
import { getProjectRole, isSystemAdmin } from "./roles";
|
||||
|
||||
const PERMISSIONS: Record<string, string[]> = {
|
||||
"subject.create": ["ADMIN", "PM", "CRA"],
|
||||
"subject.enroll": ["ADMIN", "PM", "CRA"],
|
||||
"subject.complete": ["ADMIN", "PM", "CRA"],
|
||||
"subject.drop": ["ADMIN", "PM", "CRA"],
|
||||
"ae.create": ["ADMIN", "PM", "CRA", "PV"],
|
||||
"ae.close": ["ADMIN", "PM", "PV", "CRA"],
|
||||
"faq.edit": ["ADMIN", "PM"],
|
||||
"faq.create": ["ADMIN", "PM", "CRA", "PV", "IMP"],
|
||||
"faq.reply": ["ADMIN", "PM", "CRA", "PV", "IMP"],
|
||||
"project.members.manage": ["ADMIN", "PM"],
|
||||
"site.manage": ["ADMIN", "PM"],
|
||||
"site.cra.bind": ["ADMIN", "PM"],
|
||||
"fees.contract.write": ["ADMIN", "PM"],
|
||||
"subject.create": ["ADMIN"],
|
||||
"subject.enroll": ["ADMIN"],
|
||||
"subject.complete": ["ADMIN"],
|
||||
"subject.drop": ["ADMIN"],
|
||||
"ae.create": ["ADMIN"],
|
||||
"ae.close": ["ADMIN"],
|
||||
"faq.edit": ["ADMIN"],
|
||||
"faq.create": ["ADMIN"],
|
||||
"faq.reply": ["ADMIN"],
|
||||
"project.members.manage": ["ADMIN"],
|
||||
"site.manage": ["ADMIN"],
|
||||
"site.cra.bind": ["ADMIN"],
|
||||
"fees.contract.write": ["ADMIN"],
|
||||
};
|
||||
|
||||
const REASONS: Record<string, string> = {
|
||||
@@ -40,13 +40,37 @@ export const usePermission = () => {
|
||||
|
||||
const systemAdmin = computed(() => isSystemAdmin(auth.user));
|
||||
const projectRole = computed(() => getProjectRole(study.currentStudy, study.currentStudyRole));
|
||||
const projectPermissions = computed(() => study.currentPermissions);
|
||||
|
||||
const can = (action: string): boolean => {
|
||||
if (systemAdmin.value) return true;
|
||||
const allowList = PERMISSIONS[action];
|
||||
if (!allowList) return false;
|
||||
if (!projectRole.value) return false;
|
||||
return allowList.includes(projectRole.value);
|
||||
const permissionMap: Record<string, { module: string; action: "read" | "write" }> = {
|
||||
"subject.create": { module: "subjects", action: "write" },
|
||||
"subject.enroll": { module: "subjects", action: "write" },
|
||||
"subject.complete": { module: "subjects", action: "write" },
|
||||
"subject.drop": { module: "subjects", action: "write" },
|
||||
"ae.create": { module: "risk_issues", action: "write" },
|
||||
"ae.close": { module: "risk_issues", action: "write" },
|
||||
"project.overview.read": { module: "project_overview", action: "read" },
|
||||
"faq.edit": { module: "faq", action: "write" },
|
||||
"faq.create": { module: "faq", action: "write" },
|
||||
"faq.reply": { module: "faq", action: "write" },
|
||||
"knowledge.notes.write": { module: "shared_library", action: "write" },
|
||||
"shared.library.read": { module: "shared_library", action: "read" },
|
||||
"shared.library.write": { module: "shared_library", action: "write" },
|
||||
"project.members.manage": { module: "project_members", action: "write" },
|
||||
"site.manage": { module: "sites", action: "write" },
|
||||
"site.cra.bind": { module: "sites", action: "write" },
|
||||
"fees.contract.write": { module: "fees", action: "write" },
|
||||
"fees.attachment.delete": { module: "fees", action: "write" },
|
||||
"file.attachment.delete": { module: "file_versions", action: "write" },
|
||||
"audit.export.read": { module: "audit_export", action: "read" },
|
||||
};
|
||||
const mapped = permissionMap[action];
|
||||
if (!mapped) return false;
|
||||
const allowed = projectPermissions.value?.roles?.[projectRole.value]?.[mapped.module]?.[mapped.action];
|
||||
return !!allowed;
|
||||
};
|
||||
|
||||
const reason = (action: string): string => {
|
||||
|
||||
Reference in New Issue
Block a user