2025-06-23 10:22:27 -04:00
|
|
|
import mongoose from 'mongoose';
|
2025-08-02 16:14:11 -04:00
|
|
|
import {
|
|
|
|
|
ResourceType,
|
|
|
|
|
PrincipalType,
|
|
|
|
|
PrincipalModel,
|
|
|
|
|
PermissionBits,
|
|
|
|
|
} from 'librechat-data-provider';
|
2025-06-23 10:22:27 -04:00
|
|
|
import { MongoMemoryServer } from 'mongodb-memory-server';
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
import type * as t from '~/types';
|
2025-06-23 10:22:27 -04:00
|
|
|
import { createAclEntryMethods } from './aclEntry';
|
|
|
|
|
import aclEntrySchema from '~/schema/aclEntry';
|
|
|
|
|
|
|
|
|
|
let mongoServer: MongoMemoryServer;
|
|
|
|
|
let AclEntry: mongoose.Model<t.IAclEntry>;
|
|
|
|
|
let methods: ReturnType<typeof createAclEntryMethods>;
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
|
mongoServer = await MongoMemoryServer.create();
|
|
|
|
|
const mongoUri = mongoServer.getUri();
|
|
|
|
|
AclEntry = mongoose.models.AclEntry || mongoose.model('AclEntry', aclEntrySchema);
|
|
|
|
|
methods = createAclEntryMethods(mongoose);
|
|
|
|
|
await mongoose.connect(mongoUri);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
|
await mongoose.disconnect();
|
|
|
|
|
await mongoServer.stop();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await mongoose.connection.dropDatabase();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('AclEntry Model Tests', () => {
|
|
|
|
|
/** Common test data */
|
|
|
|
|
const userId = new mongoose.Types.ObjectId();
|
|
|
|
|
const groupId = new mongoose.Types.ObjectId();
|
|
|
|
|
const resourceId = new mongoose.Types.ObjectId();
|
|
|
|
|
const grantedById = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
describe('Permission Grant and Query', () => {
|
|
|
|
|
test('should grant permission to a user', async () => {
|
|
|
|
|
const entry = await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(entry).toBeDefined();
|
2025-08-02 16:02:56 -04:00
|
|
|
expect(entry?.principalType).toBe(PrincipalType.USER);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entry?.principalId?.toString()).toBe(userId.toString());
|
2025-08-02 16:14:11 -04:00
|
|
|
expect(entry?.principalModel).toBe(PrincipalModel.USER);
|
2025-08-02 16:02:56 -04:00
|
|
|
expect(entry?.resourceType).toBe(ResourceType.AGENT);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entry?.resourceId.toString()).toBe(resourceId.toString());
|
|
|
|
|
expect(entry?.permBits).toBe(PermissionBits.VIEW);
|
|
|
|
|
expect(entry?.grantedBy?.toString()).toBe(grantedById.toString());
|
|
|
|
|
expect(entry?.grantedAt).toBeInstanceOf(Date);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should grant permission to a group', async () => {
|
|
|
|
|
const entry = await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.GROUP,
|
2025-06-23 10:22:27 -04:00
|
|
|
groupId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(entry).toBeDefined();
|
2025-08-02 16:02:56 -04:00
|
|
|
expect(entry?.principalType).toBe(PrincipalType.GROUP);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entry?.principalId?.toString()).toBe(groupId.toString());
|
2025-08-02 16:14:11 -04:00
|
|
|
expect(entry?.principalModel).toBe(PrincipalModel.GROUP);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entry?.permBits).toBe(PermissionBits.VIEW | PermissionBits.EDIT);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should grant public permission', async () => {
|
|
|
|
|
const entry = await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.PUBLIC,
|
2025-06-23 10:22:27 -04:00
|
|
|
null,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(entry).toBeDefined();
|
2025-08-02 16:02:56 -04:00
|
|
|
expect(entry?.principalType).toBe(PrincipalType.PUBLIC);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entry?.principalId).toBeUndefined();
|
|
|
|
|
expect(entry?.principalModel).toBeUndefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should find entries by principal', async () => {
|
|
|
|
|
/** Create two different permissions for the same user */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
|
|
|
|
'project',
|
|
|
|
|
new mongoose.Types.ObjectId(),
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Find all entries for the user */
|
2025-08-02 16:02:56 -04:00
|
|
|
const entries = await methods.findEntriesByPrincipal(PrincipalType.USER, userId);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entries).toHaveLength(2);
|
|
|
|
|
|
|
|
|
|
/** Find entries filtered by resource type */
|
2025-08-02 16:02:56 -04:00
|
|
|
const agentEntries = await methods.findEntriesByPrincipal(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(agentEntries).toHaveLength(1);
|
2025-08-02 16:02:56 -04:00
|
|
|
expect(agentEntries[0].resourceType).toBe(ResourceType.AGENT);
|
2025-06-23 10:22:27 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should find entries by resource', async () => {
|
|
|
|
|
/** Grant permissions to different principals for the same resource */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.GROUP,
|
2025-06-23 10:22:27 -04:00
|
|
|
groupId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.PUBLIC,
|
2025-06-23 10:22:27 -04:00
|
|
|
null,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
2025-08-02 16:02:56 -04:00
|
|
|
const entries = await methods.findEntriesByResource(ResourceType.AGENT, resourceId);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entries).toHaveLength(3);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Permission Checks', () => {
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
/** Setup test data with various permissions */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.GROUP,
|
2025-06-23 10:22:27 -04:00
|
|
|
groupId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const otherResourceId = new mongoose.Types.ObjectId();
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.PUBLIC,
|
2025-06-23 10:22:27 -04:00
|
|
|
null,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
otherResourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should find entries by principals and resource', async () => {
|
|
|
|
|
const principalsList = [
|
2025-08-02 16:02:56 -04:00
|
|
|
{ principalType: PrincipalType.USER, principalId: userId },
|
|
|
|
|
{ principalType: PrincipalType.GROUP, principalId: groupId },
|
2025-06-23 10:22:27 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const entries = await methods.findEntriesByPrincipalsAndResource(
|
|
|
|
|
principalsList,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
);
|
|
|
|
|
expect(entries).toHaveLength(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should check if user has permission', async () => {
|
2025-08-02 16:02:56 -04:00
|
|
|
const principalsList = [{ principalType: PrincipalType.USER, principalId: userId }];
|
2025-06-23 10:22:27 -04:00
|
|
|
|
|
|
|
|
/** User has VIEW permission */
|
|
|
|
|
const hasViewPermission = await methods.hasPermission(
|
|
|
|
|
principalsList,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
);
|
|
|
|
|
expect(hasViewPermission).toBe(true);
|
|
|
|
|
|
|
|
|
|
/** User doesn't have EDIT permission */
|
|
|
|
|
const hasEditPermission = await methods.hasPermission(
|
|
|
|
|
principalsList,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
);
|
|
|
|
|
expect(hasEditPermission).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should check if group has permission', async () => {
|
2025-08-02 16:02:56 -04:00
|
|
|
const principalsList = [{ principalType: PrincipalType.GROUP, principalId: groupId }];
|
2025-06-23 10:22:27 -04:00
|
|
|
|
|
|
|
|
/** Group has EDIT permission */
|
|
|
|
|
const hasEditPermission = await methods.hasPermission(
|
|
|
|
|
principalsList,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
);
|
|
|
|
|
expect(hasEditPermission).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should check permission for multiple principals', async () => {
|
|
|
|
|
const principalsList = [
|
2025-08-02 16:02:56 -04:00
|
|
|
{ principalType: PrincipalType.USER, principalId: userId },
|
|
|
|
|
{ principalType: PrincipalType.GROUP, principalId: groupId },
|
2025-06-23 10:22:27 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/** User has VIEW and group has EDIT, together they should have both */
|
|
|
|
|
const hasViewPermission = await methods.hasPermission(
|
|
|
|
|
principalsList,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
);
|
|
|
|
|
expect(hasViewPermission).toBe(true);
|
|
|
|
|
|
|
|
|
|
const hasEditPermission = await methods.hasPermission(
|
|
|
|
|
principalsList,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
);
|
|
|
|
|
expect(hasEditPermission).toBe(true);
|
|
|
|
|
|
|
|
|
|
/** Neither has DELETE permission */
|
|
|
|
|
const hasDeletePermission = await methods.hasPermission(
|
|
|
|
|
principalsList,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.DELETE,
|
|
|
|
|
);
|
|
|
|
|
expect(hasDeletePermission).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should get effective permissions', async () => {
|
|
|
|
|
const principalsList = [
|
2025-08-02 16:02:56 -04:00
|
|
|
{ principalType: PrincipalType.USER, principalId: userId },
|
|
|
|
|
{ principalType: PrincipalType.GROUP, principalId: groupId },
|
2025-06-23 10:22:27 -04:00
|
|
|
];
|
|
|
|
|
|
2025-08-02 16:02:56 -04:00
|
|
|
const effective = await methods.getEffectivePermissions(
|
|
|
|
|
principalsList,
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
);
|
2025-06-23 10:22:27 -04:00
|
|
|
|
|
|
|
|
/** Combined permissions should be VIEW | EDIT */
|
🏪 feat: Agent Marketplace
bugfix: Enhance Agent and AgentCategory schemas with new fields for category, support contact, and promotion status
refactored and moved agent category methods and schema to data-schema package
🔧 fix: Merge and Rebase Conflicts
- Move AgentCategory from api/models to @packages/data-schemas structure
- Add schema, types, methods, and model following codebase conventions
- Implement auto-seeding of default categories during AppService startup
- Update marketplace controller to use new data-schemas methods
- Remove old model file and standalone seed script
refactor: unify agent marketplace to single endpoint with cursor pagination
- Replace multiple marketplace routes with unified /marketplace endpoint
- Add query string controls: category, search, limit, cursor, promoted, requiredPermission
- Implement cursor-based pagination replacing page-based system
- Integrate ACL permissions for proper access control
- Fix ObjectId constructor error in Agent model
- Update React components to use unified useGetMarketplaceAgentsQuery hook
- Enhance type safety and remove deprecated useDynamicAgentQuery
- Update tests for new marketplace architecture
-Known issues:
see more button after category switching + Unit tests
feat: add icon property to ProcessedAgentCategory interface
- Add useMarketplaceAgentsInfiniteQuery and useGetAgentCategoriesQuery to client/src/data-provider/Agents/
- Replace manual pagination in AgentGrid with infinite query pattern
- Update imports to use local data provider instead of librechat-data-provider
- Add proper permission handling with PERMISSION_BITS.VIEW/EDIT constants
- Improve agent access control by adding requiredPermission validation in backend
- Remove manual cursor/state management in favor of infinite query built-ins
- Maintain existing search and category filtering functionality
refactor: consolidate agent marketplace endpoints into main agents API and improve data management consistency
- Remove dedicated marketplace controller and routes, merging functionality into main agents v1 API
- Add countPromotedAgents function to Agent model for promoted agents count
- Enhance getListAgents handler with marketplace filtering (category, search, promoted status)
- Move getAgentCategories from marketplace to v1 controller with same functionality
- Update agent mutations to invalidate marketplace queries and handle multiple permission levels
- Improve cache management by updating all agent query variants (VIEW/EDIT permissions)
- Consolidate agent data access patterns for better maintainability and consistency
- Remove duplicate marketplace route definitions and middleware
selected view only agents injected in the drop down
fix: remove minlength validation for support contact name in agent schema
feat: add validation and error messages for agent name in AgentConfig and AgentPanel
fix: update agent permission check logic in AgentPanel to simplify condition
Fix linting WIP
Fix Unit tests WIP
ESLint fixes
eslint fix
refactor: enhance isDuplicateVersion function in Agent model for improved comparison logic
- Introduced handling for undefined/null values in array and object comparisons.
- Normalized array comparisons to treat undefined/null as empty arrays.
- Added deep comparison for objects and improved handling of primitive values.
- Enhanced projectIds comparison to ensure consistent MongoDB ObjectId handling.
refactor: remove redundant properties from IAgent interface in agent schema
chore: update localization for agent detail component and clean up imports
ci: update access middleware tests
chore: remove unused PermissionTypes import from Role model
ci: update AclEntry model tests
ci: update button accessibility labels in AgentDetail tests
refactor: update exhaustive dep. lint warning
🔧 fix: Fixed agent actions access
feat: Add role-level permissions for agent sharing people picker
- Add PEOPLE_PICKER permission type with VIEW_USERS and VIEW_GROUPS permissions
- Create custom middleware for query-aware permission validation
- Implement permission-based type filtering in PeoplePicker component
- Hide people picker UI when user lacks permissions, show only public toggle
- Support granular access: users-only, groups-only, or mixed search modes
refactor: Replace marketplace interface config with permission-based system
- 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)
🔧 fix: Redirect to New Chat if No Marketplace Access and Required Agent Name Placeholder (#8213)
* Fix: Fix the redirect to new chat page if access to marketplace is denied
* Fixed the required agent name placeholder
---------
Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com>
chore: fix tests, remove unnecessary imports
refactor: Implement permission checks for file access via agents
- Updated `hasAccessToFilesViaAgent` to utilize permission checks for VIEW and EDIT access.
- Replaced project-based access validation with permission-based checks.
- Enhanced tests to cover new permission logic and ensure proper access control for files associated with agents.
- Cleaned up imports and initialized models in test files for consistency.
refactor: Enhance test setup and cleanup for file access control
- Introduced modelsToCleanup array to track models added during tests for proper cleanup.
- Updated afterAll hooks in test files to ensure all collections are cleared and only added models are deleted.
- Improved consistency in model initialization across test files.
- Added comments for clarity on cleanup processes and test data management.
chore: Update Jest configuration and test setup for improved timeout handling
- Added a global test timeout of 30 seconds in jest.config.js.
- Configured jest.setTimeout in jestSetup.js to allow individual test overrides if needed.
- Enhanced test reliability by ensuring consistent timeout settings across all tests.
refactor: Implement file access filtering based on agent permissions
- Introduced `filterFilesByAgentAccess` function to filter files based on user access through agents.
- Updated `getFiles` and `primeFiles` functions to utilize the new filtering logic.
- Moved `hasAccessToFilesViaAgent` function from the File model to permission services, adjusting imports accordingly
- Enhanced tests to ensure proper access control and filtering behavior for files associated with agents.
fix: make support_contact field a nested object rather than a sub-document
refactor: Update support_contact field initialization in agent model
- Removed handling for empty support_contact object in createAgent function.
- Changed default value of support_contact in agent schema to undefined.
test: Add comprehensive tests for support_contact field handling and versioning
refactor: remove unused avatar upload mutation field and add informational toast for success
chore: add missing SidePanelProvider for AgentMarketplace and organize imports
fix: resolve agent selection race condition in marketplace HandleStartChat
- Set agent in localStorage before newConversation to prevent useSelectorEffects from auto-selecting previous agent
fix: resolve agent dropdown showing raw ID instead of agent info from URL
- Add proactive agent fetching when agent_id is present in URL parameters
- Inject fetched agent into agents cache so dropdowns display proper name/avatar
- Use useAgentsMap dependency to ensure proper cache initialization timing
- Prevents raw agent IDs from showing in UI when visiting shared agent links
Fix: Agents endpoint renamed to "My Agent" for less confusion with the Marketplace agents.
chore: fix ESLint issues and Test Mocks
ci: update permissions structure in loadDefaultInterface tests
- Refactored permissions for MEMORY and added new permissions for MARKETPLACE and PEOPLE_PICKER.
- Ensured consistent structure for permissions across different types.
feat: support_contact validation to allow empty email strings
2025-06-11 22:55:07 +05:30
|
|
|
expect(effective).toBe(PermissionBits.VIEW | PermissionBits.EDIT);
|
2025-06-23 10:22:27 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('Permission Modification', () => {
|
|
|
|
|
test('should revoke permission', async () => {
|
|
|
|
|
/** Grant permission first */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Check it exists */
|
2025-08-02 16:02:56 -04:00
|
|
|
const entriesBefore = await methods.findEntriesByPrincipal(PrincipalType.USER, userId);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entriesBefore).toHaveLength(1);
|
|
|
|
|
|
|
|
|
|
/** Revoke it */
|
2025-08-02 16:02:56 -04:00
|
|
|
const result = await methods.revokePermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(result.deletedCount).toBe(1);
|
|
|
|
|
|
|
|
|
|
/** Verify it's gone */
|
2025-08-02 16:02:56 -04:00
|
|
|
const entriesAfter = await methods.findEntriesByPrincipal(PrincipalType.USER, userId);
|
2025-06-23 10:22:27 -04:00
|
|
|
expect(entriesAfter).toHaveLength(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should modify permission bits - add permissions', async () => {
|
|
|
|
|
/** Start with VIEW permission */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Add EDIT permission */
|
|
|
|
|
const updated = await methods.modifyPermissionBits(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
null,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(updated).toBeDefined();
|
|
|
|
|
expect(updated?.permBits).toBe(PermissionBits.VIEW | PermissionBits.EDIT);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should modify permission bits - remove permissions', async () => {
|
|
|
|
|
/** Start with VIEW | EDIT permissions */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Remove EDIT permission */
|
|
|
|
|
const updated = await methods.modifyPermissionBits(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
null,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(updated).toBeDefined();
|
|
|
|
|
expect(updated?.permBits).toBe(PermissionBits.VIEW);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should modify permission bits - add and remove at once', async () => {
|
|
|
|
|
/** Start with VIEW permission */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Add EDIT and remove VIEW in one operation */
|
|
|
|
|
const updated = await methods.modifyPermissionBits(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
2025-08-02 16:02:56 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(updated).toBeDefined();
|
|
|
|
|
expect(updated?.permBits).toBe(PermissionBits.EDIT);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-08-03 19:24:40 -04:00
|
|
|
describe('String vs ObjectId Edge Cases', () => {
|
|
|
|
|
test('should handle string userId in grantPermission', async () => {
|
|
|
|
|
const userIdString = userId.toString();
|
|
|
|
|
|
|
|
|
|
const entry = await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userIdString, // Pass string instead of ObjectId
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(entry).toBeDefined();
|
|
|
|
|
expect(entry?.principalType).toBe(PrincipalType.USER);
|
|
|
|
|
// Should be stored as ObjectId
|
|
|
|
|
expect(entry?.principalId).toBeInstanceOf(mongoose.Types.ObjectId);
|
|
|
|
|
expect(entry?.principalId?.toString()).toBe(userIdString);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle string groupId in grantPermission', async () => {
|
|
|
|
|
const groupIdString = groupId.toString();
|
|
|
|
|
|
|
|
|
|
const entry = await methods.grantPermission(
|
|
|
|
|
PrincipalType.GROUP,
|
|
|
|
|
groupIdString, // Pass string instead of ObjectId
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(entry).toBeDefined();
|
|
|
|
|
expect(entry?.principalType).toBe(PrincipalType.GROUP);
|
|
|
|
|
// Should be stored as ObjectId
|
|
|
|
|
expect(entry?.principalId).toBeInstanceOf(mongoose.Types.ObjectId);
|
|
|
|
|
expect(entry?.principalId?.toString()).toBe(groupIdString);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle string roleId in grantPermission for ROLE type', async () => {
|
|
|
|
|
const roleString = 'admin';
|
|
|
|
|
|
|
|
|
|
const entry = await methods.grantPermission(
|
|
|
|
|
PrincipalType.ROLE,
|
|
|
|
|
roleString,
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(entry).toBeDefined();
|
|
|
|
|
expect(entry?.principalType).toBe(PrincipalType.ROLE);
|
|
|
|
|
// Should remain as string for ROLE type
|
|
|
|
|
expect(typeof entry?.principalId).toBe('string');
|
|
|
|
|
expect(entry?.principalId).toBe(roleString);
|
|
|
|
|
expect(entry?.principalModel).toBe(PrincipalModel.ROLE);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle string principalId in revokePermission', async () => {
|
|
|
|
|
// First grant permission with ObjectId
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Then revoke with string ID
|
|
|
|
|
const result = await methods.revokePermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId.toString(), // Pass string
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(result.deletedCount).toBe(1);
|
|
|
|
|
|
|
|
|
|
// Verify it's actually deleted
|
|
|
|
|
const entries = await methods.findEntriesByPrincipal(PrincipalType.USER, userId);
|
|
|
|
|
expect(entries).toHaveLength(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle string principalId in modifyPermissionBits', async () => {
|
|
|
|
|
// First grant permission with ObjectId
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Then modify with string ID
|
|
|
|
|
const updated = await methods.modifyPermissionBits(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId.toString(), // Pass string
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
null,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(updated).toBeDefined();
|
|
|
|
|
expect(updated?.permBits).toBe(PermissionBits.VIEW | PermissionBits.EDIT);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle mixed string and ObjectId in hasPermission', async () => {
|
|
|
|
|
// Grant permission with string ID
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId.toString(),
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Check permission with ObjectId in principals list
|
|
|
|
|
const hasPermWithObjectId = await methods.hasPermission(
|
|
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId }],
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
);
|
|
|
|
|
expect(hasPermWithObjectId).toBe(true);
|
|
|
|
|
|
|
|
|
|
// Check permission with string in principals list
|
|
|
|
|
const hasPermWithString = await methods.hasPermission(
|
|
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId.toString() }],
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
);
|
|
|
|
|
expect(hasPermWithString).toBe(false); // This should fail because hasPermission doesn't convert
|
|
|
|
|
|
|
|
|
|
// Check with converted ObjectId
|
|
|
|
|
const hasPermWithConvertedId = await methods.hasPermission(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
principalType: PrincipalType.USER,
|
|
|
|
|
principalId: new mongoose.Types.ObjectId(userId.toString()),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
);
|
|
|
|
|
expect(hasPermWithConvertedId).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should update existing permission when granting with string ID', async () => {
|
|
|
|
|
// First grant with ObjectId
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Grant again with string ID and different permissions
|
|
|
|
|
const updated = await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId.toString(),
|
|
|
|
|
ResourceType.AGENT,
|
|
|
|
|
resourceId,
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT | PermissionBits.DELETE,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(updated).toBeDefined();
|
|
|
|
|
expect(updated?.permBits).toBe(
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT | PermissionBits.DELETE,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Should still only be one entry
|
|
|
|
|
const entries = await methods.findEntriesByPrincipal(PrincipalType.USER, userId);
|
|
|
|
|
expect(entries).toHaveLength(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-06-23 10:22:27 -04:00
|
|
|
describe('Resource Access Queries', () => {
|
|
|
|
|
test('should find accessible resources', async () => {
|
|
|
|
|
/** Create multiple resources with different permissions */
|
|
|
|
|
const resourceId1 = new mongoose.Types.ObjectId();
|
|
|
|
|
const resourceId2 = new mongoose.Types.ObjectId();
|
|
|
|
|
const resourceId3 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
/** User can view resource 1 */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId1,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** User can view and edit resource 2 */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
userId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId2,
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Group can view resource 3 */
|
|
|
|
|
await methods.grantPermission(
|
2025-08-02 16:02:56 -04:00
|
|
|
PrincipalType.GROUP,
|
2025-06-23 10:22:27 -04:00
|
|
|
groupId,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId3,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Find resources with VIEW permission for user */
|
|
|
|
|
const userViewableResources = await methods.findAccessibleResources(
|
2025-08-02 16:02:56 -04:00
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId }],
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(userViewableResources).toHaveLength(2);
|
|
|
|
|
expect(userViewableResources.map((r) => r.toString()).sort()).toEqual(
|
|
|
|
|
[resourceId1.toString(), resourceId2.toString()].sort(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Find resources with VIEW permission for user or group */
|
|
|
|
|
const allViewableResources = await methods.findAccessibleResources(
|
|
|
|
|
[
|
2025-08-02 16:02:56 -04:00
|
|
|
{ principalType: PrincipalType.USER, principalId: userId },
|
|
|
|
|
{ principalType: PrincipalType.GROUP, principalId: groupId },
|
2025-06-23 10:22:27 -04:00
|
|
|
],
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(allViewableResources).toHaveLength(3);
|
|
|
|
|
|
|
|
|
|
/** Find resources with EDIT permission for user */
|
|
|
|
|
const editableResources = await methods.findAccessibleResources(
|
2025-08-02 16:02:56 -04:00
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId }],
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(editableResources).toHaveLength(1);
|
|
|
|
|
expect(editableResources[0].toString()).toBe(resourceId2.toString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle inherited permissions', async () => {
|
|
|
|
|
const projectId = new mongoose.Types.ObjectId();
|
|
|
|
|
const childResourceId = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
/** Grant inherited permission on child resource */
|
|
|
|
|
await AclEntry.create({
|
2025-08-02 16:02:56 -04:00
|
|
|
principalType: PrincipalType.USER,
|
2025-06-23 10:22:27 -04:00
|
|
|
principalId: userId,
|
2025-08-02 16:14:11 -04:00
|
|
|
principalModel: PrincipalModel.USER,
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
resourceType: ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId: childResourceId,
|
|
|
|
|
permBits: PermissionBits.VIEW,
|
|
|
|
|
grantedBy: grantedById,
|
|
|
|
|
inheritedFrom: projectId,
|
|
|
|
|
});
|
|
|
|
|
|
🏪 feat: Agent Marketplace
bugfix: Enhance Agent and AgentCategory schemas with new fields for category, support contact, and promotion status
refactored and moved agent category methods and schema to data-schema package
🔧 fix: Merge and Rebase Conflicts
- Move AgentCategory from api/models to @packages/data-schemas structure
- Add schema, types, methods, and model following codebase conventions
- Implement auto-seeding of default categories during AppService startup
- Update marketplace controller to use new data-schemas methods
- Remove old model file and standalone seed script
refactor: unify agent marketplace to single endpoint with cursor pagination
- Replace multiple marketplace routes with unified /marketplace endpoint
- Add query string controls: category, search, limit, cursor, promoted, requiredPermission
- Implement cursor-based pagination replacing page-based system
- Integrate ACL permissions for proper access control
- Fix ObjectId constructor error in Agent model
- Update React components to use unified useGetMarketplaceAgentsQuery hook
- Enhance type safety and remove deprecated useDynamicAgentQuery
- Update tests for new marketplace architecture
-Known issues:
see more button after category switching + Unit tests
feat: add icon property to ProcessedAgentCategory interface
- Add useMarketplaceAgentsInfiniteQuery and useGetAgentCategoriesQuery to client/src/data-provider/Agents/
- Replace manual pagination in AgentGrid with infinite query pattern
- Update imports to use local data provider instead of librechat-data-provider
- Add proper permission handling with PERMISSION_BITS.VIEW/EDIT constants
- Improve agent access control by adding requiredPermission validation in backend
- Remove manual cursor/state management in favor of infinite query built-ins
- Maintain existing search and category filtering functionality
refactor: consolidate agent marketplace endpoints into main agents API and improve data management consistency
- Remove dedicated marketplace controller and routes, merging functionality into main agents v1 API
- Add countPromotedAgents function to Agent model for promoted agents count
- Enhance getListAgents handler with marketplace filtering (category, search, promoted status)
- Move getAgentCategories from marketplace to v1 controller with same functionality
- Update agent mutations to invalidate marketplace queries and handle multiple permission levels
- Improve cache management by updating all agent query variants (VIEW/EDIT permissions)
- Consolidate agent data access patterns for better maintainability and consistency
- Remove duplicate marketplace route definitions and middleware
selected view only agents injected in the drop down
fix: remove minlength validation for support contact name in agent schema
feat: add validation and error messages for agent name in AgentConfig and AgentPanel
fix: update agent permission check logic in AgentPanel to simplify condition
Fix linting WIP
Fix Unit tests WIP
ESLint fixes
eslint fix
refactor: enhance isDuplicateVersion function in Agent model for improved comparison logic
- Introduced handling for undefined/null values in array and object comparisons.
- Normalized array comparisons to treat undefined/null as empty arrays.
- Added deep comparison for objects and improved handling of primitive values.
- Enhanced projectIds comparison to ensure consistent MongoDB ObjectId handling.
refactor: remove redundant properties from IAgent interface in agent schema
chore: update localization for agent detail component and clean up imports
ci: update access middleware tests
chore: remove unused PermissionTypes import from Role model
ci: update AclEntry model tests
ci: update button accessibility labels in AgentDetail tests
refactor: update exhaustive dep. lint warning
🔧 fix: Fixed agent actions access
feat: Add role-level permissions for agent sharing people picker
- Add PEOPLE_PICKER permission type with VIEW_USERS and VIEW_GROUPS permissions
- Create custom middleware for query-aware permission validation
- Implement permission-based type filtering in PeoplePicker component
- Hide people picker UI when user lacks permissions, show only public toggle
- Support granular access: users-only, groups-only, or mixed search modes
refactor: Replace marketplace interface config with permission-based system
- 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)
🔧 fix: Redirect to New Chat if No Marketplace Access and Required Agent Name Placeholder (#8213)
* Fix: Fix the redirect to new chat page if access to marketplace is denied
* Fixed the required agent name placeholder
---------
Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com>
chore: fix tests, remove unnecessary imports
refactor: Implement permission checks for file access via agents
- Updated `hasAccessToFilesViaAgent` to utilize permission checks for VIEW and EDIT access.
- Replaced project-based access validation with permission-based checks.
- Enhanced tests to cover new permission logic and ensure proper access control for files associated with agents.
- Cleaned up imports and initialized models in test files for consistency.
refactor: Enhance test setup and cleanup for file access control
- Introduced modelsToCleanup array to track models added during tests for proper cleanup.
- Updated afterAll hooks in test files to ensure all collections are cleared and only added models are deleted.
- Improved consistency in model initialization across test files.
- Added comments for clarity on cleanup processes and test data management.
chore: Update Jest configuration and test setup for improved timeout handling
- Added a global test timeout of 30 seconds in jest.config.js.
- Configured jest.setTimeout in jestSetup.js to allow individual test overrides if needed.
- Enhanced test reliability by ensuring consistent timeout settings across all tests.
refactor: Implement file access filtering based on agent permissions
- Introduced `filterFilesByAgentAccess` function to filter files based on user access through agents.
- Updated `getFiles` and `primeFiles` functions to utilize the new filtering logic.
- Moved `hasAccessToFilesViaAgent` function from the File model to permission services, adjusting imports accordingly
- Enhanced tests to ensure proper access control and filtering behavior for files associated with agents.
fix: make support_contact field a nested object rather than a sub-document
refactor: Update support_contact field initialization in agent model
- Removed handling for empty support_contact object in createAgent function.
- Changed default value of support_contact in agent schema to undefined.
test: Add comprehensive tests for support_contact field handling and versioning
refactor: remove unused avatar upload mutation field and add informational toast for success
chore: add missing SidePanelProvider for AgentMarketplace and organize imports
fix: resolve agent selection race condition in marketplace HandleStartChat
- Set agent in localStorage before newConversation to prevent useSelectorEffects from auto-selecting previous agent
fix: resolve agent dropdown showing raw ID instead of agent info from URL
- Add proactive agent fetching when agent_id is present in URL parameters
- Inject fetched agent into agents cache so dropdowns display proper name/avatar
- Use useAgentsMap dependency to ensure proper cache initialization timing
- Prevents raw agent IDs from showing in UI when visiting shared agent links
Fix: Agents endpoint renamed to "My Agent" for less confusion with the Marketplace agents.
chore: fix ESLint issues and Test Mocks
ci: update permissions structure in loadDefaultInterface tests
- Refactored permissions for MEMORY and added new permissions for MARKETPLACE and PEOPLE_PICKER.
- Ensured consistent structure for permissions across different types.
feat: support_contact validation to allow empty email strings
2025-06-11 22:55:07 +05:30
|
|
|
/** Get effective permissions */
|
2025-06-23 10:22:27 -04:00
|
|
|
const effective = await methods.getEffectivePermissions(
|
2025-08-02 16:02:56 -04:00
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId }],
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
ResourceType.AGENT,
|
2025-06-23 10:22:27 -04:00
|
|
|
childResourceId,
|
|
|
|
|
);
|
|
|
|
|
|
🏪 feat: Agent Marketplace
bugfix: Enhance Agent and AgentCategory schemas with new fields for category, support contact, and promotion status
refactored and moved agent category methods and schema to data-schema package
🔧 fix: Merge and Rebase Conflicts
- Move AgentCategory from api/models to @packages/data-schemas structure
- Add schema, types, methods, and model following codebase conventions
- Implement auto-seeding of default categories during AppService startup
- Update marketplace controller to use new data-schemas methods
- Remove old model file and standalone seed script
refactor: unify agent marketplace to single endpoint with cursor pagination
- Replace multiple marketplace routes with unified /marketplace endpoint
- Add query string controls: category, search, limit, cursor, promoted, requiredPermission
- Implement cursor-based pagination replacing page-based system
- Integrate ACL permissions for proper access control
- Fix ObjectId constructor error in Agent model
- Update React components to use unified useGetMarketplaceAgentsQuery hook
- Enhance type safety and remove deprecated useDynamicAgentQuery
- Update tests for new marketplace architecture
-Known issues:
see more button after category switching + Unit tests
feat: add icon property to ProcessedAgentCategory interface
- Add useMarketplaceAgentsInfiniteQuery and useGetAgentCategoriesQuery to client/src/data-provider/Agents/
- Replace manual pagination in AgentGrid with infinite query pattern
- Update imports to use local data provider instead of librechat-data-provider
- Add proper permission handling with PERMISSION_BITS.VIEW/EDIT constants
- Improve agent access control by adding requiredPermission validation in backend
- Remove manual cursor/state management in favor of infinite query built-ins
- Maintain existing search and category filtering functionality
refactor: consolidate agent marketplace endpoints into main agents API and improve data management consistency
- Remove dedicated marketplace controller and routes, merging functionality into main agents v1 API
- Add countPromotedAgents function to Agent model for promoted agents count
- Enhance getListAgents handler with marketplace filtering (category, search, promoted status)
- Move getAgentCategories from marketplace to v1 controller with same functionality
- Update agent mutations to invalidate marketplace queries and handle multiple permission levels
- Improve cache management by updating all agent query variants (VIEW/EDIT permissions)
- Consolidate agent data access patterns for better maintainability and consistency
- Remove duplicate marketplace route definitions and middleware
selected view only agents injected in the drop down
fix: remove minlength validation for support contact name in agent schema
feat: add validation and error messages for agent name in AgentConfig and AgentPanel
fix: update agent permission check logic in AgentPanel to simplify condition
Fix linting WIP
Fix Unit tests WIP
ESLint fixes
eslint fix
refactor: enhance isDuplicateVersion function in Agent model for improved comparison logic
- Introduced handling for undefined/null values in array and object comparisons.
- Normalized array comparisons to treat undefined/null as empty arrays.
- Added deep comparison for objects and improved handling of primitive values.
- Enhanced projectIds comparison to ensure consistent MongoDB ObjectId handling.
refactor: remove redundant properties from IAgent interface in agent schema
chore: update localization for agent detail component and clean up imports
ci: update access middleware tests
chore: remove unused PermissionTypes import from Role model
ci: update AclEntry model tests
ci: update button accessibility labels in AgentDetail tests
refactor: update exhaustive dep. lint warning
🔧 fix: Fixed agent actions access
feat: Add role-level permissions for agent sharing people picker
- Add PEOPLE_PICKER permission type with VIEW_USERS and VIEW_GROUPS permissions
- Create custom middleware for query-aware permission validation
- Implement permission-based type filtering in PeoplePicker component
- Hide people picker UI when user lacks permissions, show only public toggle
- Support granular access: users-only, groups-only, or mixed search modes
refactor: Replace marketplace interface config with permission-based system
- 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)
🔧 fix: Redirect to New Chat if No Marketplace Access and Required Agent Name Placeholder (#8213)
* Fix: Fix the redirect to new chat page if access to marketplace is denied
* Fixed the required agent name placeholder
---------
Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com>
chore: fix tests, remove unnecessary imports
refactor: Implement permission checks for file access via agents
- Updated `hasAccessToFilesViaAgent` to utilize permission checks for VIEW and EDIT access.
- Replaced project-based access validation with permission-based checks.
- Enhanced tests to cover new permission logic and ensure proper access control for files associated with agents.
- Cleaned up imports and initialized models in test files for consistency.
refactor: Enhance test setup and cleanup for file access control
- Introduced modelsToCleanup array to track models added during tests for proper cleanup.
- Updated afterAll hooks in test files to ensure all collections are cleared and only added models are deleted.
- Improved consistency in model initialization across test files.
- Added comments for clarity on cleanup processes and test data management.
chore: Update Jest configuration and test setup for improved timeout handling
- Added a global test timeout of 30 seconds in jest.config.js.
- Configured jest.setTimeout in jestSetup.js to allow individual test overrides if needed.
- Enhanced test reliability by ensuring consistent timeout settings across all tests.
refactor: Implement file access filtering based on agent permissions
- Introduced `filterFilesByAgentAccess` function to filter files based on user access through agents.
- Updated `getFiles` and `primeFiles` functions to utilize the new filtering logic.
- Moved `hasAccessToFilesViaAgent` function from the File model to permission services, adjusting imports accordingly
- Enhanced tests to ensure proper access control and filtering behavior for files associated with agents.
fix: make support_contact field a nested object rather than a sub-document
refactor: Update support_contact field initialization in agent model
- Removed handling for empty support_contact object in createAgent function.
- Changed default value of support_contact in agent schema to undefined.
test: Add comprehensive tests for support_contact field handling and versioning
refactor: remove unused avatar upload mutation field and add informational toast for success
chore: add missing SidePanelProvider for AgentMarketplace and organize imports
fix: resolve agent selection race condition in marketplace HandleStartChat
- Set agent in localStorage before newConversation to prevent useSelectorEffects from auto-selecting previous agent
fix: resolve agent dropdown showing raw ID instead of agent info from URL
- Add proactive agent fetching when agent_id is present in URL parameters
- Inject fetched agent into agents cache so dropdowns display proper name/avatar
- Use useAgentsMap dependency to ensure proper cache initialization timing
- Prevents raw agent IDs from showing in UI when visiting shared agent links
Fix: Agents endpoint renamed to "My Agent" for less confusion with the Marketplace agents.
chore: fix ESLint issues and Test Mocks
ci: update permissions structure in loadDefaultInterface tests
- Refactored permissions for MEMORY and added new permissions for MARKETPLACE and PEOPLE_PICKER.
- Ensured consistent structure for permissions across different types.
feat: support_contact validation to allow empty email strings
2025-06-11 22:55:07 +05:30
|
|
|
/** Should have VIEW permission from inherited entry */
|
|
|
|
|
expect(effective).toBe(PermissionBits.VIEW);
|
2025-06-23 10:22:27 -04:00
|
|
|
});
|
|
|
|
|
});
|
2025-12-04 21:37:23 +01:00
|
|
|
|
|
|
|
|
describe('Batch Permission Queries', () => {
|
|
|
|
|
test('should get effective permissions for multiple resources in single query', async () => {
|
|
|
|
|
const resource1 = new mongoose.Types.ObjectId();
|
|
|
|
|
const resource2 = new mongoose.Types.ObjectId();
|
|
|
|
|
const resource3 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
/** Grant different permissions to different resources */
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource1,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource2,
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.GROUP,
|
|
|
|
|
groupId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource3,
|
|
|
|
|
PermissionBits.DELETE,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Get permissions for all resources */
|
|
|
|
|
const permissionsMap = await methods.getEffectivePermissionsForResources(
|
|
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId }],
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
[resource1, resource2, resource3],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(permissionsMap.size).toBe(2); // Only resource1 and resource2 for user
|
|
|
|
|
expect(permissionsMap.get(resource1.toString())).toBe(PermissionBits.VIEW);
|
2025-12-15 17:47:32 -05:00
|
|
|
expect(permissionsMap.get(resource2.toString())).toBe(
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
);
|
2025-12-04 21:37:23 +01:00
|
|
|
expect(permissionsMap.get(resource3.toString())).toBeUndefined(); // User has no access
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should combine permissions from multiple principals in batch query', async () => {
|
|
|
|
|
const resource1 = new mongoose.Types.ObjectId();
|
|
|
|
|
const resource2 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
/** User has VIEW on both resources */
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource1,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource2,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Group has EDIT on resource1 */
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.GROUP,
|
|
|
|
|
groupId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource1,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Get combined permissions for user + group */
|
|
|
|
|
const permissionsMap = await methods.getEffectivePermissionsForResources(
|
|
|
|
|
[
|
|
|
|
|
{ principalType: PrincipalType.USER, principalId: userId },
|
|
|
|
|
{ principalType: PrincipalType.GROUP, principalId: groupId },
|
|
|
|
|
],
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
[resource1, resource2],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(permissionsMap.size).toBe(2);
|
|
|
|
|
/** Resource1 should have VIEW | EDIT (from user + group) */
|
2025-12-15 17:47:32 -05:00
|
|
|
expect(permissionsMap.get(resource1.toString())).toBe(
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
);
|
2025-12-04 21:37:23 +01:00
|
|
|
/** Resource2 should have only VIEW (from user) */
|
|
|
|
|
expect(permissionsMap.get(resource2.toString())).toBe(PermissionBits.VIEW);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle empty resource list', async () => {
|
|
|
|
|
const permissionsMap = await methods.getEffectivePermissionsForResources(
|
|
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId }],
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(permissionsMap.size).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle resources with no permissions', async () => {
|
|
|
|
|
const resource1 = new mongoose.Types.ObjectId();
|
|
|
|
|
const resource2 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
/** Only grant permission to resource1 */
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource1,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const permissionsMap = await methods.getEffectivePermissionsForResources(
|
|
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId }],
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
[resource1, resource2], // resource2 has no permissions
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(permissionsMap.size).toBe(1);
|
|
|
|
|
expect(permissionsMap.get(resource1.toString())).toBe(PermissionBits.VIEW);
|
|
|
|
|
expect(permissionsMap.get(resource2.toString())).toBeUndefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should include public permissions in batch query', async () => {
|
|
|
|
|
const resource1 = new mongoose.Types.ObjectId();
|
|
|
|
|
const resource2 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
/** User has VIEW on resource1 */
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource1,
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Public has VIEW on resource2 */
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.PUBLIC,
|
|
|
|
|
null,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource2,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Query with user + public principals */
|
|
|
|
|
const permissionsMap = await methods.getEffectivePermissionsForResources(
|
|
|
|
|
[
|
|
|
|
|
{ principalType: PrincipalType.USER, principalId: userId },
|
|
|
|
|
{ principalType: PrincipalType.PUBLIC },
|
|
|
|
|
],
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
[resource1, resource2],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(permissionsMap.size).toBe(2);
|
2025-12-15 17:47:32 -05:00
|
|
|
expect(permissionsMap.get(resource1.toString())).toBe(
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
);
|
2025-12-04 21:37:23 +01:00
|
|
|
expect(permissionsMap.get(resource2.toString())).toBe(PermissionBits.VIEW);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle large batch efficiently', async () => {
|
|
|
|
|
/** Create 50 resources with various permissions */
|
|
|
|
|
const resources = Array.from({ length: 50 }, () => new mongoose.Types.ObjectId());
|
|
|
|
|
|
|
|
|
|
/** Grant permissions to first 30 resources */
|
|
|
|
|
for (let i = 0; i < 30; i++) {
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resources[i],
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Grant group permissions to resources 20-40 (overlap with user) */
|
|
|
|
|
for (let i = 20; i < 40; i++) {
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.GROUP,
|
|
|
|
|
groupId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resources[i],
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
const permissionsMap = await methods.getEffectivePermissionsForResources(
|
|
|
|
|
[
|
|
|
|
|
{ principalType: PrincipalType.USER, principalId: userId },
|
|
|
|
|
{ principalType: PrincipalType.GROUP, principalId: groupId },
|
|
|
|
|
],
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resources,
|
|
|
|
|
);
|
|
|
|
|
const duration = Date.now() - startTime;
|
|
|
|
|
|
|
|
|
|
/** Should be reasonably fast (under 1 second for 50 resources) */
|
|
|
|
|
expect(duration).toBeLessThan(1000);
|
|
|
|
|
|
|
|
|
|
/** Verify results */
|
|
|
|
|
expect(permissionsMap.size).toBe(40); // Resources 0-39 have permissions
|
|
|
|
|
|
|
|
|
|
/** Resources 0-19: USER VIEW only */
|
|
|
|
|
for (let i = 0; i < 20; i++) {
|
|
|
|
|
expect(permissionsMap.get(resources[i].toString())).toBe(PermissionBits.VIEW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Resources 20-29: USER VIEW | GROUP EDIT */
|
|
|
|
|
for (let i = 20; i < 30; i++) {
|
2025-12-15 17:47:32 -05:00
|
|
|
expect(permissionsMap.get(resources[i].toString())).toBe(
|
|
|
|
|
PermissionBits.VIEW | PermissionBits.EDIT,
|
|
|
|
|
);
|
2025-12-04 21:37:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Resources 30-39: GROUP EDIT only */
|
|
|
|
|
for (let i = 30; i < 40; i++) {
|
|
|
|
|
expect(permissionsMap.get(resources[i].toString())).toBe(PermissionBits.EDIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Resources 40-49: No permissions */
|
|
|
|
|
for (let i = 40; i < 50; i++) {
|
|
|
|
|
expect(permissionsMap.get(resources[i].toString())).toBeUndefined();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle mixed ObjectId and string resource IDs', async () => {
|
|
|
|
|
const resource1 = new mongoose.Types.ObjectId();
|
|
|
|
|
const resource2 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource1,
|
|
|
|
|
PermissionBits.VIEW,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await methods.grantPermission(
|
|
|
|
|
PrincipalType.USER,
|
|
|
|
|
userId,
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
resource2,
|
|
|
|
|
PermissionBits.EDIT,
|
|
|
|
|
grantedById,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** Pass mix of ObjectId and string */
|
|
|
|
|
const permissionsMap = await methods.getEffectivePermissionsForResources(
|
|
|
|
|
[{ principalType: PrincipalType.USER, principalId: userId }],
|
|
|
|
|
ResourceType.MCPSERVER,
|
|
|
|
|
[resource1, resource2.toString()], // Mix of ObjectId and string
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(permissionsMap.size).toBe(2);
|
|
|
|
|
expect(permissionsMap.get(resource1.toString())).toBe(PermissionBits.VIEW);
|
|
|
|
|
expect(permissionsMap.get(resource2.toString())).toBe(PermissionBits.EDIT);
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-06-23 10:22:27 -04:00
|
|
|
});
|