mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🔖 feat: Enhance Bookmarks UX, add RBAC, toggle via librechat.yaml (#3747)
* chore: update package version to 0.7.416 * chore: Update Role.js imports order * refactor: move updateTagsInConvo to tags route, add RBAC for tags * refactor: add updateTagsInConvoOptions * fix: loading state for bookmark form * refactor: update primaryText class in TitleButton component * refactor: remove duplicate bookmarks and theming * refactor: update EditIcon component to use React.forwardRef * refactor: add _id field to tConversationTagSchema * refactor: remove promises * refactor: move mutation logic from BookmarkForm -> BookmarkEditDialog * refactor: update button class in BookmarkForm component * fix: conversation mutations and add better logging to useConversationTagMutation * refactor: update logger message in BookmarkEditDialog component * refactor: improve UI consistency in BookmarkNav and NewChat components * refactor: update logger message in BookmarkEditDialog component * refactor: Add tags prop to BookmarkForm component * refactor: Update BookmarkForm to avoid tag mutation if the tag already exists; also close dialog on submission programmatically * refactor: general role helper function to support updating access permissions for different permission types * refactor: Update getLatestText function to handle undefined values in message.content * refactor: Update useHasAccess hook to handle null role values for authenticated users * feat: toggle bookmarks access * refactor: Update PromptsCommand to handle access permissions for prompts * feat: updateConversationSelector * refactor: rename `vars` to `tagToDelete` for clarity * fix: prevent recreation of deleted tags in BookmarkMenu on Item Click * ci: mock updateBookmarksAccess function * ci: mock updateBookmarksAccess function
This commit is contained in:
parent
366e4c5adb
commit
f86e9dd04c
39 changed files with 530 additions and 298 deletions
|
|
@ -1,10 +1,11 @@
|
|||
const {
|
||||
SystemRoles,
|
||||
CacheKeys,
|
||||
SystemRoles,
|
||||
roleDefaults,
|
||||
PermissionTypes,
|
||||
Permissions,
|
||||
removeNullishValues,
|
||||
promptPermissionsSchema,
|
||||
bookmarkPermissionsSchema,
|
||||
} = require('librechat-data-provider');
|
||||
const getLogStores = require('~/cache/getLogStores');
|
||||
const Role = require('~/models/schema/roleSchema');
|
||||
|
|
@ -69,37 +70,52 @@ const updateRoleByName = async function (roleName, updates) {
|
|||
}
|
||||
};
|
||||
|
||||
const permissionSchemas = {
|
||||
[PermissionTypes.PROMPTS]: promptPermissionsSchema,
|
||||
[PermissionTypes.BOOKMARKS]: bookmarkPermissionsSchema,
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the Prompt access for a specific role.
|
||||
* @param {SystemRoles} roleName - The role to update the prompt access for.
|
||||
* @param {boolean | undefined} [value] - The new value for the prompt access.
|
||||
* Updates access permissions for a specific role and permission type.
|
||||
* @param {SystemRoles} roleName - The role to update.
|
||||
* @param {PermissionTypes} permissionType - The type of permission to update.
|
||||
* @param {Object.<Permissions, boolean>} permissions - Permissions to update and their values.
|
||||
*/
|
||||
async function updatePromptsAccess(roleName, value) {
|
||||
if (typeof value === 'undefined') {
|
||||
async function updateAccessPermissions(roleName, permissionType, _permissions) {
|
||||
const permissions = removeNullishValues(_permissions);
|
||||
if (Object.keys(permissions).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedUpdates = promptPermissionsSchema.partial().parse({ [Permissions.USE]: value });
|
||||
const role = await getRoleByName(roleName);
|
||||
if (!role) {
|
||||
if (!role || !permissionSchemas[permissionType]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const mergedUpdates = {
|
||||
[PermissionTypes.PROMPTS]: {
|
||||
...role[PermissionTypes.PROMPTS],
|
||||
...parsedUpdates,
|
||||
await updateRoleByName(roleName, {
|
||||
[permissionType]: {
|
||||
...role[permissionType],
|
||||
...permissionSchemas[permissionType].partial().parse(permissions),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
await updateRoleByName(roleName, mergedUpdates);
|
||||
logger.info(`Updated '${roleName}' role prompts 'USE' permission to: ${value}`);
|
||||
Object.entries(permissions).forEach(([permission, value]) =>
|
||||
logger.info(
|
||||
`Updated '${roleName}' role ${permissionType} '${permission}' permission to: ${value}`,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error('Failed to update USER role prompts USE permission:', error);
|
||||
logger.error(`Failed to update ${roleName} role ${permissionType} permissions:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
const updatePromptsAccess = (roleName, permissions) =>
|
||||
updateAccessPermissions(roleName, PermissionTypes.PROMPTS, permissions);
|
||||
|
||||
const updateBookmarksAccess = (roleName, permissions) =>
|
||||
updateAccessPermissions(roleName, PermissionTypes.BOOKMARKS, permissions);
|
||||
|
||||
/**
|
||||
* Initialize default roles in the system.
|
||||
* Creates the default roles (ADMIN, USER) if they don't exist in the database.
|
||||
|
|
@ -123,4 +139,5 @@ module.exports = {
|
|||
initializeRoles,
|
||||
updateRoleByName,
|
||||
updatePromptsAccess,
|
||||
updateBookmarksAccess,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue