mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +01:00
- Add MARKETPLACE permission type to handle marketplace access control - Update interface configuration to use role-based marketplace settings (admin/user) - Replace direct marketplace boolean config with permission-based checks - Modify frontend components to use marketplace permissions instead of interface config - Update agent query hooks to use marketplace permissions for determining permission levels - Add marketplace configuration structure similar to peoplePicker in YAML config - Backend now sets MARKETPLACE permissions based on interface configuration - When marketplace enabled: users get agents with EDIT permissions in dropdown lists (builder mode) - When marketplace disabled: users get agents with VIEW permissions in dropdown lists (browse mode)
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
import { Schema } from 'mongoose';
|
|
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
|
import type { IRole } from '~/types';
|
|
|
|
// Create a sub-schema for permissions. Notice we disable _id for this subdocument.
|
|
const rolePermissionsSchema = new Schema(
|
|
{
|
|
[PermissionTypes.BOOKMARKS]: {
|
|
[Permissions.USE]: { type: Boolean, default: true },
|
|
},
|
|
[PermissionTypes.PROMPTS]: {
|
|
[Permissions.SHARED_GLOBAL]: { type: Boolean, default: false },
|
|
[Permissions.USE]: { type: Boolean, default: true },
|
|
[Permissions.CREATE]: { type: Boolean, default: true },
|
|
},
|
|
[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 },
|
|
},
|
|
[PermissionTypes.AGENTS]: {
|
|
[Permissions.SHARED_GLOBAL]: { type: Boolean, default: false },
|
|
[Permissions.USE]: { type: Boolean, default: true },
|
|
[Permissions.CREATE]: { type: Boolean, default: true },
|
|
},
|
|
[PermissionTypes.MULTI_CONVO]: {
|
|
[Permissions.USE]: { type: Boolean, default: true },
|
|
},
|
|
[PermissionTypes.TEMPORARY_CHAT]: {
|
|
[Permissions.USE]: { type: Boolean, default: true },
|
|
},
|
|
[PermissionTypes.RUN_CODE]: {
|
|
[Permissions.USE]: { type: Boolean, default: true },
|
|
},
|
|
[PermissionTypes.WEB_SEARCH]: {
|
|
[Permissions.USE]: { type: Boolean, default: true },
|
|
},
|
|
[PermissionTypes.PEOPLE_PICKER]: {
|
|
[Permissions.VIEW_USERS]: { type: Boolean, default: false },
|
|
[Permissions.VIEW_GROUPS]: { type: Boolean, default: false },
|
|
},
|
|
[PermissionTypes.MARKETPLACE]: {
|
|
[Permissions.USE]: { type: Boolean, default: false },
|
|
},
|
|
},
|
|
{ _id: false },
|
|
);
|
|
|
|
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,
|
|
},
|
|
[PermissionTypes.MARKETPLACE]: { [Permissions.USE]: false },
|
|
}),
|
|
},
|
|
});
|
|
|
|
export default roleSchema;
|