forked from baron/baron-sso
feat: improve Worksmobile tenant sync handling
This commit is contained in:
@@ -12,6 +12,8 @@ export type TenantFilterTarget = {
|
||||
parentId?: string | null;
|
||||
name?: string;
|
||||
tenantName?: string;
|
||||
visibility?: string;
|
||||
config?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type HanmacFamilyUserTarget = {
|
||||
@@ -43,6 +45,29 @@ type OrgChartLoginOptions = {
|
||||
returnTo?: string;
|
||||
};
|
||||
|
||||
export const GPDTDC_GRADE_OPTIONS = [
|
||||
"연구원",
|
||||
"선임",
|
||||
"책임",
|
||||
"수석",
|
||||
"부사장",
|
||||
"사장",
|
||||
] as const;
|
||||
|
||||
export const HANMAC_FAMILY_GRADE_OPTIONS = [
|
||||
"사원",
|
||||
"대리",
|
||||
"과장",
|
||||
"차장",
|
||||
"부장",
|
||||
"이사",
|
||||
"상무",
|
||||
"전무",
|
||||
"부사장",
|
||||
"사장",
|
||||
"회장",
|
||||
] as const;
|
||||
|
||||
function isSystemTenant(tenant: TenantFilterTarget) {
|
||||
const slug = tenant.slug?.trim().toLowerCase();
|
||||
const type = tenant.type?.trim().toUpperCase();
|
||||
@@ -56,6 +81,73 @@ function isSystemTenant(tenant: TenantFilterTarget) {
|
||||
);
|
||||
}
|
||||
|
||||
function resolveTenantTarget<T extends TenantFilterTarget>(
|
||||
target: TenantFilterTarget | undefined,
|
||||
tenants: T[],
|
||||
) {
|
||||
if (!target) return undefined;
|
||||
const tenantID = target.id ?? target.tenantId ?? "";
|
||||
const tenantSlug = target.slug ?? target.tenantSlug ?? "";
|
||||
return (
|
||||
tenants.find((tenant) => tenantID && tenant.id === tenantID) ??
|
||||
tenants.find(
|
||||
(tenant) =>
|
||||
tenantSlug &&
|
||||
tenant.slug?.trim().toLowerCase() === tenantSlug.trim().toLowerCase(),
|
||||
) ??
|
||||
target
|
||||
);
|
||||
}
|
||||
|
||||
function isGPDTDCTenant<T extends TenantFilterTarget>(
|
||||
target: TenantFilterTarget | undefined,
|
||||
tenants: T[],
|
||||
) {
|
||||
const tenant = resolveTenantTarget(target, tenants);
|
||||
if (!tenant) return false;
|
||||
|
||||
const tenantById = new Map(
|
||||
tenants
|
||||
.filter((item) => item.id?.trim())
|
||||
.map((item) => [item.id as string, item]),
|
||||
);
|
||||
let current: TenantFilterTarget | undefined = tenant;
|
||||
const visited = new Set<string>();
|
||||
|
||||
while (current) {
|
||||
const slug = current.slug?.trim().toLowerCase();
|
||||
if (slug === "gpdtdc") {
|
||||
return true;
|
||||
}
|
||||
const parentId = current.parentId ?? "";
|
||||
if (!parentId || visited.has(parentId)) {
|
||||
return false;
|
||||
}
|
||||
visited.add(parentId);
|
||||
current = tenantById.get(parentId);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getTenantGradeOptions<T extends TenantFilterTarget>(
|
||||
target: TenantFilterTarget | undefined,
|
||||
tenants: T[],
|
||||
) {
|
||||
return isGPDTDCTenant(target, tenants)
|
||||
? [...GPDTDC_GRADE_OPTIONS]
|
||||
: [...HANMAC_FAMILY_GRADE_OPTIONS];
|
||||
}
|
||||
|
||||
function isPublicRepresentativeTenant(tenant: TenantFilterTarget) {
|
||||
const visibility = String(
|
||||
tenant.visibility ?? tenant.config?.visibility ?? "public",
|
||||
)
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
return visibility !== "internal" && visibility !== "private";
|
||||
}
|
||||
|
||||
function isInTenantSubtree<T extends TenantFilterTarget>(
|
||||
tenant: T,
|
||||
rootTenantId: string,
|
||||
@@ -187,6 +279,7 @@ export function filterNonHanmacFamilyTenants<T extends TenantFilterTarget>(
|
||||
return tenants.filter(
|
||||
(tenant) =>
|
||||
!isSystemTenant(tenant) &&
|
||||
isPublicRepresentativeTenant(tenant) &&
|
||||
!isInTenantSubtree(tenant, rootTenantId, tenantById),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user