This commit is contained in:
freedakgmail
2025-11-23 18:03:04 +08:00
parent 9cdd751a56
commit e44dd0bd95
489 changed files with 264491 additions and 4157 deletions
@@ -197,10 +197,26 @@ const authOptions = {
"use strict";
__turbopack_context__.s([
"canDeleteTree",
()=>canDeleteTree,
"canEditTree",
()=>canEditTree,
"canInviteCollaborators",
()=>canInviteCollaborators,
"checkPermission",
()=>checkPermission,
"getRoleDescription",
()=>getRoleDescription,
"getRoleDisplayName",
()=>getRoleDisplayName,
"getRolePermissions",
()=>getRolePermissions,
"permissions",
()=>permissions,
"requireAuth",
()=>requireAuth
()=>requireAuth,
"requirePermission",
()=>requirePermission
]);
var __TURBOPACK__imported__module__$5b$project$5d2f$Documents$2f$go$2d$new$2f$chinese$2d$family$2d$tree$2f$lib$2f$prisma$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Documents/go-new/chinese-family-tree/lib/prisma.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$externals$5d2f40$prisma$2f$client__$5b$external$5d$__$2840$prisma$2f$client$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/@prisma/client [external] (@prisma/client, cjs)");
@@ -250,6 +266,163 @@ async function requireAuth(userId) {
}
return userId;
}
const permissions = {
// ==================== 增加权限 ====================
/**
* 是否可以创建/添加成员
* OWNER | EDITOR | VIEWER
*/ canCreate: (role)=>{
return role === "OWNER" || role === "EDITOR";
},
/**
* 是否可以创建家族树
* OWNER | EDITOR | VIEWER
*/ canCreateTree: (role)=>{
return role === "OWNER" || role === "EDITOR";
},
// ==================== 修改权限 ====================
/**
* 是否可以编辑/更新成员信息
* OWNER | EDITOR | VIEWER
*/ canUpdate: (role)=>{
return role === "OWNER" || role === "EDITOR";
},
/**
* 是否可以导入数据
* OWNER | EDITOR | VIEWER
*/ canImport: (role)=>{
return role === "OWNER" || role === "EDITOR";
},
// ==================== 删除权限 ====================
/**
* 是否可以删除成员
* OWNER | EDITOR | VIEWER
*/ canDeleteMember: (role)=>{
return role === "OWNER" || role === "EDITOR";
},
/**
* 是否可以删除家族树
* OWNER | EDITOR | VIEWER
*/ canDeleteTree: (role)=>{
return role === "OWNER";
},
/**
* 是否可以清空数据
* OWNER | EDITOR | VIEWER
*/ canClearData: (role)=>{
return role === "OWNER";
},
// ==================== 协作者管理权限 ====================
/**
* 是否可以邀请协作者
* OWNER | EDITOR | VIEWER
*/ canInviteCollaborators: (role)=>{
return role === "OWNER";
},
/**
* 是否可以移除协作者
* OWNER | EDITOR | VIEWER
*/ canRemoveCollaborators: (role)=>{
return role === "OWNER";
},
/**
* 是否可以管理协作者(邀请和移除)
* OWNER | EDITOR | VIEWER
*/ canManageCollaborators: (role)=>{
return role === "OWNER";
},
// ==================== 查看权限 ====================
/**
* 是否可以查看信息
* OWNER | EDITOR | VIEWER
*/ canView: (role)=>{
return true //
;
},
/**
* 是否可以搜索和查询
* OWNER | EDITOR | VIEWER
*/ canSearch: (role)=>{
return true //
;
},
/**
* 是否可以导出数据
* OWNER | EDITOR | VIEWER
*/ canExport: (role)=>{
return true //
;
},
/**
* 是否可以打印
* OWNER | EDITOR | VIEWER
*/ canPrint: (role)=>{
return true //
;
}
};
function canEditTree(role) {
return permissions.canUpdate(role);
}
function canDeleteTree(role) {
return permissions.canDeleteTree(role);
}
function canInviteCollaborators(role) {
return permissions.canInviteCollaborators(role);
}
function requirePermission(role, permissionCheck, errorMessage = "您没有权限执行此操作") {
if (!permissionCheck(role)) {
throw new Error(errorMessage);
}
}
function getRoleDisplayName(role) {
const roleNames = {
OWNER: "所有者",
EDITOR: "编辑者",
VIEWER: "查看者"
};
return roleNames[role] || role;
}
function getRoleDescription(role) {
const descriptions = {
OWNER: "拥有全部权限,可以管理家族树和协作者",
EDITOR: "可以添加、编辑和删除成员,但不能删除家族树或管理协作者",
VIEWER: "只能查看、搜索和导出数据,不能进行任何修改操作"
};
return descriptions[role] || "";
}
function getRolePermissions(role) {
const allPermissions = {
OWNER: [
"查看所有信息",
"搜索和筛选",
"导出和打印",
"添加成员",
"编辑成员",
"删除成员",
"导入数据",
"邀请协作者",
"移除协作者",
"删除家族树",
"清空数据"
],
EDITOR: [
"查看所有信息",
"搜索和筛选",
"导出和打印",
"添加成员",
"编辑成员",
"删除成员",
"导入数据"
],
VIEWER: [
"查看所有信息",
"搜索和筛选",
"导出和打印"
]
};
return allPermissions[role] || [];
}
}),
"[project]/Documents/go-new/chinese-family-tree/app/api/trees/[treeId]/members/route.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";