forked from bai/curriculum-project-hub
chore(filelib-web): 授权成员单元格只留头像+名称,userId 与飞书 ID 拆为独立两列
GrantDto 增加 principalOpenId(USER 主体的 feishuOpenId),GROUP 行两列显示 —; 搜索过滤同步覆盖 openId。
This commit is contained in:
@@ -27,6 +27,8 @@ export interface GrantDto {
|
||||
readonly principalId: string;
|
||||
/** 主体显示名(用户 displayName / 组 name);主体已删时为 null,前端回落 principalId。 */
|
||||
readonly principalName: string | null;
|
||||
/** USER 主体的飞书 openId;GROUP 或主体已删时为 null。 */
|
||||
readonly principalOpenId: string | null;
|
||||
readonly role: FileLibRole;
|
||||
readonly isCreatorGrant: boolean;
|
||||
readonly createdAt: Date;
|
||||
@@ -38,13 +40,14 @@ function toDto(grant: FileLibGrant): GrantDto {
|
||||
principalType: grant.principalType,
|
||||
principalId: grant.principalId,
|
||||
principalName: null,
|
||||
principalOpenId: null,
|
||||
role: grant.role,
|
||||
isCreatorGrant: grant.isCreatorGrant,
|
||||
createdAt: grant.createdAt,
|
||||
};
|
||||
}
|
||||
|
||||
/** 批量回填主体显示名(两次查询,不做 per-row 往返)。可在事务内调用。 */
|
||||
/** 批量回填主体显示名与飞书 openId(两次查询,不做 per-row 往返)。可在事务内调用。 */
|
||||
async function withPrincipalNames(
|
||||
prisma: Pick<PrismaClient, "user" | "memberGroup">,
|
||||
grants: readonly GrantDto[],
|
||||
@@ -53,7 +56,10 @@ async function withPrincipalNames(
|
||||
const groupIds = [...new Set(grants.filter((g) => g.principalType === "GROUP").map((g) => g.principalId))];
|
||||
const users = userIds.length === 0
|
||||
? []
|
||||
: await prisma.user.findMany({ where: { id: { in: userIds } }, select: { id: true, displayName: true } });
|
||||
: await prisma.user.findMany({
|
||||
where: { id: { in: userIds } },
|
||||
select: { id: true, displayName: true, feishuOpenId: true },
|
||||
});
|
||||
const groups = groupIds.length === 0
|
||||
? []
|
||||
: await prisma.memberGroup.findMany({ where: { id: { in: groupIds } }, select: { id: true, name: true } });
|
||||
@@ -61,7 +67,12 @@ async function withPrincipalNames(
|
||||
...users.map((u) => [u.id, u.displayName] as const),
|
||||
...groups.map((g) => [g.id, g.name] as const),
|
||||
]);
|
||||
return grants.map((g) => ({ ...g, principalName: nameById.get(g.principalId) ?? null }));
|
||||
const openIdById = new Map<string, string>(users.map((u) => [u.id, u.feishuOpenId] as const));
|
||||
return grants.map((g) => ({
|
||||
...g,
|
||||
principalName: nameById.get(g.principalId) ?? null,
|
||||
principalOpenId: g.principalType === "USER" ? openIdById.get(g.principalId) ?? null : null,
|
||||
}));
|
||||
}
|
||||
|
||||
type Tx = Prisma.TransactionClient;
|
||||
|
||||
Reference in New Issue
Block a user