feat(小宝预警): 增加权限与数据键

This commit is contained in:
Script Generator
2026-06-29 17:13:54 +08:00
parent 5a41904ba6
commit 46a002f817
6 changed files with 79 additions and 5 deletions

View File

@@ -0,0 +1,15 @@
import type { RoleItem } from './members';
import { DEFAULT_ROLE_PERMISSIONS } from './permissions';
export function mergePresetRolePermissions(roles: RoleItem[]): { roles: RoleItem[]; changed: boolean } {
let changed = false;
const next = roles.map((role) => {
const defaults = DEFAULT_ROLE_PERMISSIONS[role.id];
if (!defaults || role.permissions.includes('*')) return role;
const merged = Array.from(new Set([...role.permissions, ...defaults]));
if (merged.length === role.permissions.length) return role;
changed = true;
return { ...role, permissions: merged };
});
return { roles: next, changed };
}