feat(小宝预警): 增加权限与数据键
This commit is contained in:
15
apps/web/lib/role-permission-migration.ts
Normal file
15
apps/web/lib/role-permission-migration.ts
Normal 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user