mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02: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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,50 +8,50 @@ import type { IRole } from '~/types';
|
|||
const rolePermissionsSchema = new Schema(
|
||||
{
|
||||
[PermissionTypes.BOOKMARKS]: {
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.PROMPTS]: {
|
||||
[Permissions.SHARED_GLOBAL]: { type: Boolean, default: false },
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.CREATE]: { type: Boolean, default: true },
|
||||
[Permissions.SHARED_GLOBAL]: { type: Boolean },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
[Permissions.CREATE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.MEMORIES]: {
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.CREATE]: { type: Boolean, default: true },
|
||||
[Permissions.UPDATE]: { type: Boolean, default: true },
|
||||
[Permissions.READ]: { type: Boolean, default: true },
|
||||
[Permissions.OPT_OUT]: { type: Boolean, default: true },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
[Permissions.CREATE]: { type: Boolean },
|
||||
[Permissions.UPDATE]: { type: Boolean },
|
||||
[Permissions.READ]: { type: Boolean },
|
||||
[Permissions.OPT_OUT]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.AGENTS]: {
|
||||
[Permissions.SHARED_GLOBAL]: { type: Boolean, default: false },
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.CREATE]: { type: Boolean, default: true },
|
||||
[Permissions.SHARED_GLOBAL]: { type: Boolean },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
[Permissions.CREATE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.MULTI_CONVO]: {
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.TEMPORARY_CHAT]: {
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.RUN_CODE]: {
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.WEB_SEARCH]: {
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.PEOPLE_PICKER]: {
|
||||
[Permissions.VIEW_USERS]: { type: Boolean, default: false },
|
||||
[Permissions.VIEW_GROUPS]: { type: Boolean, default: false },
|
||||
[Permissions.VIEW_ROLES]: { type: Boolean, default: false },
|
||||
[Permissions.VIEW_USERS]: { type: Boolean },
|
||||
[Permissions.VIEW_GROUPS]: { type: Boolean },
|
||||
[Permissions.VIEW_ROLES]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.MARKETPLACE]: {
|
||||
[Permissions.USE]: { type: Boolean, default: false },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.FILE_SEARCH]: {
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
},
|
||||
[PermissionTypes.FILE_CITATIONS]: {
|
||||
[Permissions.USE]: { type: Boolean, default: true },
|
||||
[Permissions.USE]: { type: Boolean },
|
||||
},
|
||||
},
|
||||
{ _id: false },
|
||||
|
@ -61,37 +61,6 @@ const roleSchema: Schema<IRole> = new Schema({
|
|||
name: { type: String, required: true, unique: true, index: true },
|
||||
permissions: {
|
||||
type: rolePermissionsSchema,
|
||||
default: () => ({
|
||||
[PermissionTypes.BOOKMARKS]: { [Permissions.USE]: true },
|
||||
[PermissionTypes.PROMPTS]: {
|
||||
[Permissions.SHARED_GLOBAL]: false,
|
||||
[Permissions.USE]: true,
|
||||
[Permissions.CREATE]: true,
|
||||
},
|
||||
[PermissionTypes.MEMORIES]: {
|
||||
[Permissions.USE]: true,
|
||||
[Permissions.CREATE]: true,
|
||||
[Permissions.UPDATE]: true,
|
||||
[Permissions.READ]: true,
|
||||
},
|
||||
[PermissionTypes.AGENTS]: {
|
||||
[Permissions.SHARED_GLOBAL]: false,
|
||||
[Permissions.USE]: true,
|
||||
[Permissions.CREATE]: true,
|
||||
},
|
||||
[PermissionTypes.MULTI_CONVO]: { [Permissions.USE]: true },
|
||||
[PermissionTypes.TEMPORARY_CHAT]: { [Permissions.USE]: true },
|
||||
[PermissionTypes.RUN_CODE]: { [Permissions.USE]: true },
|
||||
[PermissionTypes.WEB_SEARCH]: { [Permissions.USE]: true },
|
||||
[PermissionTypes.PEOPLE_PICKER]: {
|
||||
[Permissions.VIEW_USERS]: false,
|
||||
[Permissions.VIEW_GROUPS]: false,
|
||||
[Permissions.VIEW_ROLES]: false,
|
||||
},
|
||||
[PermissionTypes.MARKETPLACE]: { [Permissions.USE]: false },
|
||||
[PermissionTypes.FILE_SEARCH]: { [Permissions.USE]: true },
|
||||
[PermissionTypes.FILE_CITATIONS]: { [Permissions.USE]: true },
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue