mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +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,5 +1,10 @@
|
|||
import mongoose from 'mongoose';
|
||||
import { ResourceType, PermissionBits, PrincipalType } from 'librechat-data-provider';
|
||||
import {
|
||||
ResourceType,
|
||||
PrincipalType,
|
||||
PrincipalModel,
|
||||
PermissionBits,
|
||||
} from 'librechat-data-provider';
|
||||
import { MongoMemoryServer } from 'mongodb-memory-server';
|
||||
import type * as t from '~/types';
|
||||
import { createAclEntryMethods } from './aclEntry';
|
||||
|
|
@ -47,7 +52,7 @@ describe('AclEntry Model Tests', () => {
|
|||
expect(entry).toBeDefined();
|
||||
expect(entry?.principalType).toBe(PrincipalType.USER);
|
||||
expect(entry?.principalId?.toString()).toBe(userId.toString());
|
||||
expect(entry?.principalModel).toBe('User');
|
||||
expect(entry?.principalModel).toBe(PrincipalModel.USER);
|
||||
expect(entry?.resourceType).toBe(ResourceType.AGENT);
|
||||
expect(entry?.resourceId.toString()).toBe(resourceId.toString());
|
||||
expect(entry?.permBits).toBe(PermissionBits.VIEW);
|
||||
|
|
@ -68,7 +73,7 @@ describe('AclEntry Model Tests', () => {
|
|||
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);
|
||||
expect(entry?.permBits).toBe(PermissionBits.VIEW | PermissionBits.EDIT);
|
||||
});
|
||||
|
||||
|
|
@ -469,7 +474,7 @@ describe('AclEntry Model Tests', () => {
|
|||
await AclEntry.create({
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: userId,
|
||||
principalModel: 'User',
|
||||
principalModel: PrincipalModel.USER,
|
||||
resourceType: ResourceType.AGENT,
|
||||
resourceId: childResourceId,
|
||||
permBits: PermissionBits.VIEW,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue