38 lines
778 B
TypeScript
38 lines
778 B
TypeScript
import {
|
||
isSuperAdmin,
|
||
isSystemAdmin,
|
||
} from '@/lib/department-permission'
|
||
|
||
export interface MaterialAuthorizationUser {
|
||
id: string
|
||
role?: string | null
|
||
isSuperAdmin?: boolean | null
|
||
}
|
||
|
||
export interface MaterialAuthorizationTarget {
|
||
userId: string
|
||
}
|
||
|
||
/**
|
||
* 素材写操作的最小统一授权:
|
||
* - 素材所有者
|
||
* - 系统管理员(兼容 ADMIN / SYSTEM_ADMIN)
|
||
* - 超级管理员
|
||
*
|
||
* 部门查看权限不能自动升级为素材写权限。
|
||
*/
|
||
export async function canManageMaterial(
|
||
user: MaterialAuthorizationUser,
|
||
material: MaterialAuthorizationTarget,
|
||
): Promise<boolean> {
|
||
if (
|
||
material.userId === user.id ||
|
||
isSystemAdmin(user.role) ||
|
||
user.isSuperAdmin === true
|
||
) {
|
||
return true
|
||
}
|
||
|
||
return isSuperAdmin(user.id)
|
||
}
|