1
0
forked from baron/baron-sso

Format orgfront code check targets

This commit is contained in:
2026-04-30 16:07:18 +09:00
parent 7d893431d1
commit c6190bbab6
2 changed files with 51 additions and 48 deletions

View File

@@ -1,63 +1,63 @@
import type { TenantSummary, UserSummary } from "../../lib/adminApi";
type UserAppointment = {
tenantId?: string;
tenantSlug?: string;
jobTitle?: string;
position?: string;
tenantId?: string;
tenantSlug?: string;
jobTitle?: string;
position?: string;
};
type TenantIdentity = Pick<TenantSummary, "id" | "slug">;
function normalizeText(value: unknown) {
return typeof value === "string" ? value.trim() : "";
return typeof value === "string" ? value.trim() : "";
}
function getUserAppointments(user: UserSummary): UserAppointment[] {
const rawAppointments = user.metadata?.additionalAppointments;
if (!Array.isArray(rawAppointments)) return [];
const rawAppointments = user.metadata?.additionalAppointments;
if (!Array.isArray(rawAppointments)) return [];
return rawAppointments
.filter(
(item): item is Record<string, unknown> =>
typeof item === "object" && item !== null,
)
.map((item) => ({
tenantId: normalizeText(item.tenantId),
tenantSlug: normalizeText(item.tenantSlug),
jobTitle: normalizeText(item.jobTitle),
position: normalizeText(item.position),
}));
return rawAppointments
.filter(
(item): item is Record<string, unknown> =>
typeof item === "object" && item !== null,
)
.map((item) => ({
tenantId: normalizeText(item.tenantId),
tenantSlug: normalizeText(item.tenantSlug),
jobTitle: normalizeText(item.jobTitle),
position: normalizeText(item.position),
}));
}
export function getUserOrgProfile(user: UserSummary, tenant?: TenantIdentity) {
const appointment = getUserAppointments(user).find((item) => {
if (tenant?.id && item.tenantId === tenant.id) return true;
if (
tenant?.slug &&
item.tenantSlug &&
item.tenantSlug.toLowerCase() === tenant.slug.toLowerCase()
) {
return true;
}
return false;
});
const appointment = getUserAppointments(user).find((item) => {
if (tenant?.id && item.tenantId === tenant.id) return true;
if (
tenant?.slug &&
item.tenantSlug &&
item.tenantSlug.toLowerCase() === tenant.slug.toLowerCase()
) {
return true;
}
return false;
});
return {
jobTitle: appointment?.jobTitle || normalizeText(user.jobTitle),
position: appointment?.position || normalizeText(user.position),
};
return {
jobTitle: appointment?.jobTitle || normalizeText(user.jobTitle),
position: appointment?.position || normalizeText(user.position),
};
}
export function getOrgChartUserDisplayName(
user: UserSummary,
tenant?: TenantIdentity,
user: UserSummary,
tenant?: TenantIdentity,
) {
const { jobTitle, position } = getUserOrgProfile(user, tenant);
const baseName = user.name.trim();
const { jobTitle, position } = getUserOrgProfile(user, tenant);
const baseName = user.name.trim();
if (jobTitle && position) return `${baseName} ${position}[${jobTitle}]`;
if (jobTitle) return `${baseName}[${jobTitle}]`;
if (position) return `${baseName} ${position}`;
return baseName;
if (jobTitle && position) return `${baseName} ${position}[${jobTitle}]`;
if (jobTitle) return `${baseName}[${jobTitle}]`;
if (position) return `${baseName} ${position}`;
return baseName;
}

View File

@@ -21,13 +21,16 @@ test("orgfront login auto parameter starts OIDC authorization", async ({
},
);
await page.route("http://localhost:5000/oidc/oauth2/auth**", async (route) => {
authorizationURL = route.request().url();
await route.fulfill({
contentType: "text/html",
body: "<!doctype html><title>Authorization captured</title>",
});
});
await page.route(
"http://localhost:5000/oidc/oauth2/auth**",
async (route) => {
authorizationURL = route.request().url();
await route.fulfill({
contentType: "text/html",
body: "<!doctype html><title>Authorization captured</title>",
});
},
);
await page.goto("/login?auto=1&returnTo=%2Fpicker");