mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 02:40:14 +01:00
🎏 refactor: Streamline Role Permissions from Interface Config
This commit is contained in:
parent
b742c8c7f9
commit
e8ddd279fd
5 changed files with 1008 additions and 231 deletions
|
|
@ -15,14 +15,12 @@ export function createRoleMethods(mongoose: typeof import('mongoose')) {
|
|||
const defaultPerms = roleDefaults[roleName].permissions;
|
||||
|
||||
if (!role) {
|
||||
// Create new role if it doesn't exist.
|
||||
role = new Role(roleDefaults[roleName]);
|
||||
} else {
|
||||
// Ensure role.permissions is defined.
|
||||
const permissions = role.toObject()?.permissions ?? {};
|
||||
role.permissions = role.permissions || {};
|
||||
// For each permission type in defaults, add it if missing.
|
||||
for (const permType of Object.keys(defaultPerms)) {
|
||||
if (role.permissions[permType] == null) {
|
||||
if (permissions[permType] == null || Object.keys(permissions[permType]).length === 0) {
|
||||
role.permissions[permType] = defaultPerms[permType as keyof typeof defaultPerms];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue