48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
const BRAND_CENTER_SEGMENT = '品牌中心'
|
|
|
|
const BRAND_CENTER_ADMIN_ROLES = new Set(['ADMIN', 'SYSTEM_ADMIN'])
|
|
|
|
export function isBrandCenterOrganizationPath(value: unknown): boolean {
|
|
return String(value ?? '')
|
|
.split('/')
|
|
.map((segment) => segment.trim())
|
|
.filter(Boolean)
|
|
.includes(BRAND_CENTER_SEGMENT)
|
|
}
|
|
|
|
export function hasBrandCenterAccess(input: {
|
|
role?: unknown
|
|
isSuperAdmin?: unknown
|
|
employmentState?: unknown
|
|
departmentPaths?: unknown[]
|
|
}): boolean {
|
|
const role = String(input.role ?? '')
|
|
if (input.isSuperAdmin === true || BRAND_CENTER_ADMIN_ROLES.has(role)) return true
|
|
if (input.employmentState === 'RESIGNED') return false
|
|
return (input.departmentPaths ?? []).some(isBrandCenterOrganizationPath)
|
|
}
|
|
|
|
const BRAND_CENTER_RESTRICTED_PREFIXES = [
|
|
'/workspaces',
|
|
'/admin',
|
|
'/organization',
|
|
'/performance-survey',
|
|
'/work-review',
|
|
'/teacher',
|
|
]
|
|
|
|
export function isBrandCenterRestrictedPath(pathname: string): boolean {
|
|
return pathname === '/' || BRAND_CENTER_RESTRICTED_PREFIXES.some(
|
|
(prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`),
|
|
)
|
|
}
|
|
|
|
export function shouldRedirectToStandaloneMaterialLibrary(
|
|
pathname: string,
|
|
canAccessBrandCenter: unknown,
|
|
): boolean {
|
|
return canAccessBrandCenter !== true && (
|
|
pathname === '/materials' || isBrandCenterRestrictedPath(pathname)
|
|
)
|
|
}
|