43 lines
933 B
TypeScript
43 lines
933 B
TypeScript
import {
|
|
canUserDownloadMaterial,
|
|
isSuperAdmin,
|
|
isSystemAdmin,
|
|
} from '@/lib/department-permission'
|
|
|
|
export interface SkuRouteSessionUser {
|
|
id: string
|
|
role?: string | null
|
|
department?: string | null
|
|
managedDepartment?: string | null
|
|
isSuperAdmin?: boolean | null
|
|
}
|
|
|
|
export interface SkuRouteMaterial {
|
|
userId: string
|
|
materialType: string
|
|
}
|
|
|
|
export async function canManageSkuMaterial(
|
|
user: SkuRouteSessionUser,
|
|
material: Pick<SkuRouteMaterial, 'userId'>,
|
|
): Promise<boolean> {
|
|
if (material.userId === user.id || isSystemAdmin(user.role) || user.isSuperAdmin === true) {
|
|
return true
|
|
}
|
|
|
|
return isSuperAdmin(user.id)
|
|
}
|
|
|
|
export async function canDownloadSkuMaterial(
|
|
user: SkuRouteSessionUser,
|
|
material: SkuRouteMaterial,
|
|
): Promise<boolean> {
|
|
return canUserDownloadMaterial(
|
|
user.department,
|
|
user.role || 'USER',
|
|
user.managedDepartment,
|
|
material.materialType,
|
|
user.id,
|
|
)
|
|
}
|