forked from baron/baron-sso
Format orgfront code check targets
This commit is contained in:
@@ -1,63 +1,63 @@
|
|||||||
import type { TenantSummary, UserSummary } from "../../lib/adminApi";
|
import type { TenantSummary, UserSummary } from "../../lib/adminApi";
|
||||||
|
|
||||||
type UserAppointment = {
|
type UserAppointment = {
|
||||||
tenantId?: string;
|
tenantId?: string;
|
||||||
tenantSlug?: string;
|
tenantSlug?: string;
|
||||||
jobTitle?: string;
|
jobTitle?: string;
|
||||||
position?: string;
|
position?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type TenantIdentity = Pick<TenantSummary, "id" | "slug">;
|
type TenantIdentity = Pick<TenantSummary, "id" | "slug">;
|
||||||
|
|
||||||
function normalizeText(value: unknown) {
|
function normalizeText(value: unknown) {
|
||||||
return typeof value === "string" ? value.trim() : "";
|
return typeof value === "string" ? value.trim() : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserAppointments(user: UserSummary): UserAppointment[] {
|
function getUserAppointments(user: UserSummary): UserAppointment[] {
|
||||||
const rawAppointments = user.metadata?.additionalAppointments;
|
const rawAppointments = user.metadata?.additionalAppointments;
|
||||||
if (!Array.isArray(rawAppointments)) return [];
|
if (!Array.isArray(rawAppointments)) return [];
|
||||||
|
|
||||||
return rawAppointments
|
return rawAppointments
|
||||||
.filter(
|
.filter(
|
||||||
(item): item is Record<string, unknown> =>
|
(item): item is Record<string, unknown> =>
|
||||||
typeof item === "object" && item !== null,
|
typeof item === "object" && item !== null,
|
||||||
)
|
)
|
||||||
.map((item) => ({
|
.map((item) => ({
|
||||||
tenantId: normalizeText(item.tenantId),
|
tenantId: normalizeText(item.tenantId),
|
||||||
tenantSlug: normalizeText(item.tenantSlug),
|
tenantSlug: normalizeText(item.tenantSlug),
|
||||||
jobTitle: normalizeText(item.jobTitle),
|
jobTitle: normalizeText(item.jobTitle),
|
||||||
position: normalizeText(item.position),
|
position: normalizeText(item.position),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUserOrgProfile(user: UserSummary, tenant?: TenantIdentity) {
|
export function getUserOrgProfile(user: UserSummary, tenant?: TenantIdentity) {
|
||||||
const appointment = getUserAppointments(user).find((item) => {
|
const appointment = getUserAppointments(user).find((item) => {
|
||||||
if (tenant?.id && item.tenantId === tenant.id) return true;
|
if (tenant?.id && item.tenantId === tenant.id) return true;
|
||||||
if (
|
if (
|
||||||
tenant?.slug &&
|
tenant?.slug &&
|
||||||
item.tenantSlug &&
|
item.tenantSlug &&
|
||||||
item.tenantSlug.toLowerCase() === tenant.slug.toLowerCase()
|
item.tenantSlug.toLowerCase() === tenant.slug.toLowerCase()
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
jobTitle: appointment?.jobTitle || normalizeText(user.jobTitle),
|
jobTitle: appointment?.jobTitle || normalizeText(user.jobTitle),
|
||||||
position: appointment?.position || normalizeText(user.position),
|
position: appointment?.position || normalizeText(user.position),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOrgChartUserDisplayName(
|
export function getOrgChartUserDisplayName(
|
||||||
user: UserSummary,
|
user: UserSummary,
|
||||||
tenant?: TenantIdentity,
|
tenant?: TenantIdentity,
|
||||||
) {
|
) {
|
||||||
const { jobTitle, position } = getUserOrgProfile(user, tenant);
|
const { jobTitle, position } = getUserOrgProfile(user, tenant);
|
||||||
const baseName = user.name.trim();
|
const baseName = user.name.trim();
|
||||||
|
|
||||||
if (jobTitle && position) return `${baseName} ${position}[${jobTitle}]`;
|
if (jobTitle && position) return `${baseName} ${position}[${jobTitle}]`;
|
||||||
if (jobTitle) return `${baseName}[${jobTitle}]`;
|
if (jobTitle) return `${baseName}[${jobTitle}]`;
|
||||||
if (position) return `${baseName} ${position}`;
|
if (position) return `${baseName} ${position}`;
|
||||||
return baseName;
|
return baseName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,16 @@ test("orgfront login auto parameter starts OIDC authorization", async ({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await page.route("http://localhost:5000/oidc/oauth2/auth**", async (route) => {
|
await page.route(
|
||||||
authorizationURL = route.request().url();
|
"http://localhost:5000/oidc/oauth2/auth**",
|
||||||
await route.fulfill({
|
async (route) => {
|
||||||
contentType: "text/html",
|
authorizationURL = route.request().url();
|
||||||
body: "<!doctype html><title>Authorization captured</title>",
|
await route.fulfill({
|
||||||
});
|
contentType: "text/html",
|
||||||
});
|
body: "<!doctype html><title>Authorization captured</title>",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await page.goto("/login?auto=1&returnTo=%2Fpicker");
|
await page.goto("/login?auto=1&returnTo=%2Fpicker");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user