|
|
@@ -46,6 +46,7 @@ export interface PermissionItem {
|
|
|
has_permission?: boolean
|
|
|
checked?: boolean
|
|
|
selected?: boolean
|
|
|
+ is_only_open_for_root?: number
|
|
|
children?: PermissionItem[]
|
|
|
actions?: PermissionItem[]
|
|
|
permissions?: PermissionItem[]
|
|
|
@@ -79,13 +80,14 @@ function normalizePermissionList(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-function permissionHasRole(permission: PermissionItem) {
|
|
|
- return (
|
|
|
- permission.has_permission ??
|
|
|
- permission.checked ??
|
|
|
- permission.selected ??
|
|
|
- false
|
|
|
- )
|
|
|
+function permissionHasRole(permission: PermissionItem, isSuperAdmin: boolean) {
|
|
|
+ if (isSuperAdmin) {
|
|
|
+ // 超级管理员:is_only_open_for_root=1 直接显示,否则看 has_permission
|
|
|
+ if (permission.is_only_open_for_root === 1) return true
|
|
|
+ return permission.has_permission ?? false
|
|
|
+ }
|
|
|
+ // 其余角色:只看 has_permission
|
|
|
+ return permission.has_permission ?? false
|
|
|
}
|
|
|
|
|
|
function getPermissionCode(permission: PermissionItem) {
|
|
|
@@ -104,6 +106,7 @@ function getPermissionCode(permission: PermissionItem) {
|
|
|
|
|
|
function collectPermissionCodes(
|
|
|
permissions: PermissionItem[],
|
|
|
+ isSuperAdmin: boolean,
|
|
|
codes = new Set<string>()
|
|
|
) {
|
|
|
for (const permission of permissions) {
|
|
|
@@ -117,14 +120,20 @@ function collectPermissionCodes(
|
|
|
|
|
|
for (const relation of childPermissions) {
|
|
|
const target = relation.ExtPermission ?? relation
|
|
|
- if (permissionHasRole(relation) || permissionHasRole(target)) {
|
|
|
+ if (
|
|
|
+ permissionHasRole(relation, isSuperAdmin) ||
|
|
|
+ permissionHasRole(target, isSuperAdmin)
|
|
|
+ ) {
|
|
|
const code = getPermissionCode(target)
|
|
|
if (code) codes.add(code)
|
|
|
}
|
|
|
- collectPermissionCodes([target], codes)
|
|
|
+ collectPermissionCodes([target], isSuperAdmin, codes)
|
|
|
}
|
|
|
|
|
|
- if (permissionHasRole(permission) || codes.size > beforeSize) {
|
|
|
+ if (
|
|
|
+ permissionHasRole(permission, isSuperAdmin) ||
|
|
|
+ codes.size > beforeSize
|
|
|
+ ) {
|
|
|
const code = getPermissionCode(permission)
|
|
|
if (code) codes.add(code)
|
|
|
}
|
|
|
@@ -134,10 +143,11 @@ function collectPermissionCodes(
|
|
|
}
|
|
|
|
|
|
export function toCurrentPermissionSnapshot(
|
|
|
- permissions: PermissionItem[]
|
|
|
+ permissions: PermissionItem[],
|
|
|
+ isSuperAdmin = false
|
|
|
): CurrentPermissionSnapshot {
|
|
|
return {
|
|
|
- codes: [...collectPermissionCodes(permissions)],
|
|
|
+ codes: [...collectPermissionCodes(permissions, isSuperAdmin)],
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -158,6 +168,11 @@ export async function getPermissionsWithRole(
|
|
|
return normalizePermissionList(res.data)
|
|
|
}
|
|
|
|
|
|
-export async function getCurrentPermissionsWithRole(): Promise<CurrentPermissionSnapshot> {
|
|
|
- return toCurrentPermissionSnapshot(await getPermissionsWithRole())
|
|
|
+export async function getCurrentPermissionsWithRole(
|
|
|
+ isSuperAdmin = false
|
|
|
+): Promise<CurrentPermissionSnapshot> {
|
|
|
+ return toCurrentPermissionSnapshot(
|
|
|
+ await getPermissionsWithRole(),
|
|
|
+ isSuperAdmin
|
|
|
+ )
|
|
|
}
|