feat: split settings management pages
This commit is contained in:
@@ -4,7 +4,7 @@ import { jsonFailure, jsonSuccess, readJsonBody } from "@/modules/core/server/ap
|
||||
import { hashPassword, normalizeEmail, requirePermission, toPublicAccount } from "@/modules/core/server/auth";
|
||||
import { recordAuditLog } from "@/modules/core/server/audit";
|
||||
import { getDatabase } from "@/modules/core/server/db";
|
||||
import { hasPermission } from "@/modules/core/server/permissions";
|
||||
import { getRoleDefinitions, hasPermission } from "@/modules/core/server/permissions";
|
||||
import { accounts, memberships, organizations, roles } from "@/modules/core/server/schema";
|
||||
import { readData } from "@/modules/core/server/store";
|
||||
|
||||
@@ -30,6 +30,9 @@ export async function GET(): Promise<Response> {
|
||||
const data = await readData();
|
||||
const canReadAllAccounts = hasPermission(auth.context.permissions, "platform:manage");
|
||||
const organizationId = auth.context.organization?.id;
|
||||
const roleDefinitions = await getRoleDefinitions(organizationId);
|
||||
const roleById = new Map(roleDefinitions.map((role) => [role.id, role]));
|
||||
const organizationById = new Map(data.organizations.map((organization) => [organization.id, organization]));
|
||||
const scopedAccountIds =
|
||||
organizationId && !canReadAllAccounts
|
||||
? new Set(
|
||||
@@ -42,7 +45,17 @@ export async function GET(): Promise<Response> {
|
||||
return jsonSuccess("账号列表已加载", {
|
||||
accounts: data.accounts
|
||||
.filter((account) => !scopedAccountIds || scopedAccountIds.has(account.id))
|
||||
.map((account) => toPublicAccount(account)),
|
||||
.map((account) => {
|
||||
const membership = organizationId
|
||||
? data.memberships.find(
|
||||
(item) => item.accountId === account.id && item.organizationId === organizationId && item.status === "active",
|
||||
)
|
||||
: data.memberships.find((item) => item.accountId === account.id && item.status === "active");
|
||||
const organization = membership ? organizationById.get(membership.organizationId) : undefined;
|
||||
const platformRole = account.platformRoleId ? roleById.get(account.platformRoleId) : undefined;
|
||||
|
||||
return toPublicAccount(account, platformRole?.key ?? membership?.roleKey, organization);
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user