完全移除模块级权限系统,迁移至接口级权限

后端:
- 删除 StudyRolePermission 模型和 project_permissions API 文件
- 重写 project_permissions.py core,移除所有模块级权限函数
- 重写 permission_cache.py,移除模块级权限缓存逻辑
- 新增权限模板功能(PermissionTemplate 模型、API、服务层)
- 新增 permission_templates 数据库迁移
- 迁移 8 个模块(attachments、audit_logs、dashboard、faqs、
  faq_categories、fees_attachments、knowledge_notes、
  material_equipments、overview、subject_histories、subject_pds)
  至接口级权限检查
- 删除所有模块级权限相关测试文件,新增权限模板测试

前端:
- 删除 ProjectPermissions.vue 和 ProjectPermissionsModule.vue
- 重写 projectRoutePermissions.ts,改为基于接口级权限格式
- 更新 store/study.ts、router/index.ts、AuditLogs.vue、Projects.vue
  中的权限 API 调用,从 fetchProjectRolePermissions 改为
  fetchApiEndpointPermissions
- 清理 types/api.ts 中的旧模块级权限类型定义
- 新增 PermissionTemplateSelector.vue 组件
- 更新权限管理页面,移除模块级权限 tab

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Cheng Zhou
2026-05-15 09:07:43 +08:00
parent 3b1bdc2070
commit 20ce6bccef
55 changed files with 1971 additions and 3030 deletions
@@ -18,47 +18,52 @@
<el-option
v-for="module in uniqueModules"
:key="module"
:label="module"
:label="moduleLabel(module)"
:value="module"
/>
</el-select>
<el-select v-model="filterAction" placeholder="筛选操作" clearable style="width: 120px">
<el-option label="全部操作" value="" />
<el-option label="创建" value="create" />
<el-option label="读取" value="read" />
<el-option label="写入" value="write" />
<el-option label="更新" value="update" />
<el-option label="删除" value="delete" />
<el-option label="导出" value="export" />
</el-select>
</div>
<!-- 权限矩阵表格 -->
<div class="api-permissions-table-wrapper">
<el-table :data="filteredOperations" border stripe>
<el-table-column prop="operation_key" label="权限操作" width="200">
<el-table :data="filteredOperations" border stripe :span-method="spanMethod">
<el-table-column prop="module" label="模块" width="140">
<template #default="{ row }">
<div class="operation-cell">
<el-tag :type="getActionType(row.action)" size="small">
{{ row.action === 'read' ? '读取' : '写入' }}
</el-tag>
<span class="operation-name">{{ row.operation_key }}</span>
</div>
<span class="module-label">{{ moduleLabel(row.module) }}</span>
</template>
</el-table-column>
<el-table-column prop="description" label="描述" width="200" show-overflow-tooltip />
<el-table-column prop="module" label="模块" width="100" />
<el-table-column prop="operation_key" label="权限操作" width="200">
<template #default="{ row }">
<div class="operation-cell">
<el-tag :type="getActionType(row)" size="small">
{{ getActionLabel(row) }}
</el-tag>
<span class="operation-name">{{ row.description || row.operation_key }}</span>
</div>
</template>
</el-table-column>
<el-table-column
v-for="role in roles"
:key="role"
:label="role"
:width="100"
:width="90"
align="center"
>
<template #default="{ row }">
<el-checkbox
:model-value="isOperationAllowed(row.operation_key, role)"
@change="(val) => onPermissionChange(row.operation_key, role, val as boolean)"
@change="(val: boolean) => onPermissionChange(row.operation_key, role, val)"
/>
</template>
</el-table-column>
@@ -99,6 +104,30 @@ const filterModule = ref("");
const filterAction = ref("");
const operations = ref<Operation[]>([]);
const MODULE_LABELS: Record<string, string> = {
subjects: "参与者管理",
sites: "中心管理",
risk_issues: "风险问题",
monitoring_audit: "监查稽查",
project_members: "项目成员",
project_milestones: "项目里程碑",
project_overview: "项目总览",
fees: "合同费用",
materials: "物资管理",
material_equipments: "物资设备",
documents: "文件版本",
startup_ethics: "立项与伦理",
startup_auth: "启动与授权",
audit_export: "审计日志",
faq: "FAQ",
shared_library: "共享库",
attachments: "附件管理",
dashboard: "仪表板",
subject_histories: "参与者历史",
};
const moduleLabel = (module: string): string => MODULE_LABELS[module] || module;
// 从矩阵中提取角色列表
const roles = computed(() => {
if (!props.matrix) return [];
@@ -121,21 +150,48 @@ const uniqueModules = computed(() => {
return [...new Set(operations.value.map((o) => o.module))].sort();
});
// 过滤后的操作列表
// 过滤并按模块分组排序
const filteredOperations = computed(() => {
return operations.value.filter((operation) => {
const filtered = operations.value.filter((operation) => {
const matchSearch =
!searchText.value ||
operation.operation_key.toLowerCase().includes(searchText.value.toLowerCase()) ||
operation.description.toLowerCase().includes(searchText.value.toLowerCase());
operation.description.toLowerCase().includes(searchText.value.toLowerCase()) ||
moduleLabel(operation.module).includes(searchText.value);
const matchModule = !filterModule.value || operation.module === filterModule.value;
const matchAction = !filterAction.value || operation.action === filterAction.value;
const matchAction = !filterAction.value || getOperationVerb(operation) === filterAction.value;
return matchSearch && matchModule && matchAction;
});
// 按模块分组排序
filtered.sort((a, b) => {
if (a.module !== b.module) {
return moduleLabel(a.module).localeCompare(moduleLabel(b.module), "zh-CN");
}
return a.operation_key.localeCompare(b.operation_key);
});
return filtered;
});
// 模块列合并行
const spanMethod = ({ row, rowIndex, columnIndex }: { row: Operation; rowIndex: number; column: any; columnIndex: number }) => {
if (columnIndex === 0) {
const list = filteredOperations.value;
if (rowIndex === 0 || list[rowIndex - 1].module !== row.module) {
let count = 1;
for (let i = rowIndex + 1; i < list.length && list[i].module === row.module; i++) {
count++;
}
return { rowspan: count, colspan: 1 };
}
return { rowspan: 0, colspan: 0 };
}
return { rowspan: 1, colspan: 1 };
};
// 检查操作是否允许
const isOperationAllowed = (operation_key: string, role: string): boolean => {
if (!props.matrix || !props.matrix[role]) return false;
@@ -144,13 +200,44 @@ const isOperationAllowed = (operation_key: string, role: string): boolean => {
return typeof perm === "boolean" ? perm : perm.allowed;
};
// 获取操作的标签类型
const getActionType = (action: string): string => {
const typeMap: Record<string, string> = {
read: "info",
write: "success",
};
return typeMap[action] || "info";
// 从 operation_key 提取操作类型
const getOperationVerb = (row: Operation): string => {
const key = row.operation_key;
const suffix = key.split(":").pop() || "";
if (suffix === "create") return "create";
if (suffix === "read" || suffix === "list") return "read";
if (suffix === "update") return "update";
if (suffix === "delete") return "delete";
if (suffix === "export") return "export";
return row.action;
};
const ACTION_LABELS: Record<string, string> = {
create: "创建",
read: "读取",
update: "更新",
delete: "删除",
export: "导出",
write: "写入",
};
const ACTION_TAG_TYPES: Record<string, string> = {
create: "success",
read: "info",
update: "warning",
delete: "danger",
export: "",
write: "success",
};
const getActionLabel = (row: Operation): string => {
const verb = getOperationVerb(row);
return ACTION_LABELS[verb] || verb;
};
const getActionType = (row: Operation): string => {
const verb = getOperationVerb(row);
return ACTION_TAG_TYPES[verb] || "info";
};
// 权限变更处理
@@ -189,20 +276,20 @@ onMounted(() => {
overflow-x: auto;
}
.endpoint-cell {
.module-label {
font-weight: 600;
font-size: 13px;
color: #303133;
}
.operation-cell {
display: flex;
align-items: center;
gap: 10px;
gap: 8px;
:deep(.el-tag) {
min-width: 50px;
text-align: center;
.operation-name {
font-size: 13px;
color: #606266;
}
}
.endpoint-path {
font-family: monospace;
font-size: 12px;
color: #606266;
}
</style>