mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🔧 refactor: Integrate PrincipalModel Enum for Principal Handling
- Replaced string literals for principal models ('User', 'Group') with the new PrincipalModel enum across various models, services, and tests to enhance type safety and consistency.
- Updated permission handling in multiple files to utilize the PrincipalModel enum, improving maintainability and reducing potential errors.
- Ensured all relevant tests reflect these changes to maintain coverage and functionality.
This commit is contained in:
parent
49d1cefe71
commit
28d63dab71
10 changed files with 61 additions and 30 deletions
|
|
@ -1,7 +1,12 @@
|
|||
const mongoose = require('mongoose');
|
||||
const { RoleBits, createModels } = require('@librechat/data-schemas');
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
const { AccessRoleIds, ResourceType, PrincipalType } = require('librechat-data-provider');
|
||||
const {
|
||||
ResourceType,
|
||||
AccessRoleIds,
|
||||
PrincipalType,
|
||||
PrincipalModel,
|
||||
} = require('librechat-data-provider');
|
||||
const {
|
||||
bulkUpdateResourcePermissions,
|
||||
getEffectivePermissions,
|
||||
|
|
@ -87,10 +92,10 @@ describe('PermissionService', () => {
|
|||
});
|
||||
|
||||
expect(entry).toBeDefined();
|
||||
expect(entry.principalType).toBe('user');
|
||||
expect(entry.principalType).toBe(PrincipalType.USER);
|
||||
expect(entry.principalId.toString()).toBe(userId.toString());
|
||||
expect(entry.principalModel).toBe('User');
|
||||
expect(entry.resourceType).toBe('agent');
|
||||
expect(entry.principalModel).toBe(PrincipalModel.USER);
|
||||
expect(entry.resourceType).toBe(ResourceType.AGENT);
|
||||
expect(entry.resourceId.toString()).toBe(resourceId.toString());
|
||||
|
||||
// Get the role to verify the permission bits are correctly set
|
||||
|
|
@ -114,7 +119,7 @@ describe('PermissionService', () => {
|
|||
expect(entry).toBeDefined();
|
||||
expect(entry.principalType).toBe(PrincipalType.GROUP);
|
||||
expect(entry.principalId.toString()).toBe(groupId.toString());
|
||||
expect(entry.principalModel).toBe('Group');
|
||||
expect(entry.principalModel).toBe(PrincipalModel.GROUP);
|
||||
|
||||
// Get the role to verify the permission bits are correctly set
|
||||
const role = await findRoleByIdentifier(AccessRoleIds.AGENT_EDITOR);
|
||||
|
|
@ -433,7 +438,7 @@ describe('PermissionService', () => {
|
|||
await AclEntry.create({
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: userId,
|
||||
principalModel: 'User',
|
||||
principalModel: PrincipalModel.USER,
|
||||
resourceType: ResourceType.AGENT,
|
||||
resourceId: childResourceId,
|
||||
permBits: RoleBits.VIEWER,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue