mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🔧 refactor: Add and use PrincipalType Enum
- Replaced string literals for principal types ('user', 'group', 'public') with the new PrincipalType enum across various models, services, and tests for improved type safety and consistency.
- Updated permission handling in multiple files to utilize the PrincipalType enum, enhancing maintainability and reducing potential errors.
- Ensured all relevant tests reflect these changes to maintain coverage and functionality.
This commit is contained in:
parent
0262c25989
commit
49d1cefe71
23 changed files with 253 additions and 219 deletions
|
|
@ -1,5 +1,5 @@
|
|||
const mongoose = require('mongoose');
|
||||
const { ResourceType } = require('librechat-data-provider');
|
||||
const { ResourceType, PrincipalType } = require('librechat-data-provider');
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
const { canAccessAgentResource } = require('./canAccessAgentResource');
|
||||
const { User, Role, AclEntry } = require('~/db/models');
|
||||
|
|
@ -97,7 +97,7 @@ describe('canAccessAgentResource middleware', () => {
|
|||
|
||||
// Create ACL entry for the author (owner permissions)
|
||||
await AclEntry.create({
|
||||
principalType: 'user',
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: testUser._id,
|
||||
principalModel: 'User',
|
||||
resourceType: ResourceType.AGENT,
|
||||
|
|
@ -134,7 +134,7 @@ describe('canAccessAgentResource middleware', () => {
|
|||
|
||||
// Create ACL entry for the other user (owner)
|
||||
await AclEntry.create({
|
||||
principalType: 'user',
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: otherUser._id,
|
||||
principalModel: 'User',
|
||||
resourceType: ResourceType.AGENT,
|
||||
|
|
@ -175,7 +175,7 @@ describe('canAccessAgentResource middleware', () => {
|
|||
|
||||
// Create ACL entry granting view permission to test user
|
||||
await AclEntry.create({
|
||||
principalType: 'user',
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: testUser._id,
|
||||
principalModel: 'User',
|
||||
resourceType: ResourceType.AGENT,
|
||||
|
|
@ -212,7 +212,7 @@ describe('canAccessAgentResource middleware', () => {
|
|||
|
||||
// Create ACL entry granting only view permission
|
||||
await AclEntry.create({
|
||||
principalType: 'user',
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: testUser._id,
|
||||
principalModel: 'User',
|
||||
resourceType: ResourceType.AGENT,
|
||||
|
|
@ -259,7 +259,7 @@ describe('canAccessAgentResource middleware', () => {
|
|||
|
||||
// Create ACL entry for the author
|
||||
await AclEntry.create({
|
||||
principalType: 'user',
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: testUser._id,
|
||||
principalModel: 'User',
|
||||
resourceType: ResourceType.AGENT,
|
||||
|
|
@ -295,7 +295,7 @@ describe('canAccessAgentResource middleware', () => {
|
|||
|
||||
// Create ACL entry with all permissions for the owner
|
||||
await AclEntry.create({
|
||||
principalType: 'user',
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: testUser._id,
|
||||
principalModel: 'User',
|
||||
resourceType: ResourceType.AGENT,
|
||||
|
|
@ -355,7 +355,7 @@ describe('canAccessAgentResource middleware', () => {
|
|||
|
||||
// Create ACL entry for the author
|
||||
await AclEntry.create({
|
||||
principalType: 'user',
|
||||
principalType: PrincipalType.USER,
|
||||
principalId: testUser._id,
|
||||
principalModel: 'User',
|
||||
resourceType: ResourceType.AGENT,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue