mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-09 20:18:50 +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,18 +1,19 @@
|
|||
import { Schema } from 'mongoose';
|
||||
import { PrincipalType } from 'librechat-data-provider';
|
||||
import type { IAclEntry } from '~/types';
|
||||
|
||||
const aclEntrySchema = new Schema<IAclEntry>(
|
||||
{
|
||||
principalType: {
|
||||
type: String,
|
||||
enum: ['user', 'group', 'public'],
|
||||
enum: Object.values(PrincipalType),
|
||||
required: true,
|
||||
},
|
||||
principalId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
refPath: 'principalModel',
|
||||
required: function (this: IAclEntry) {
|
||||
return this.principalType !== 'public';
|
||||
return this.principalType !== PrincipalType.PUBLIC;
|
||||
},
|
||||
index: true,
|
||||
},
|
||||
|
|
@ -20,7 +21,7 @@ const aclEntrySchema = new Schema<IAclEntry>(
|
|||
type: String,
|
||||
enum: ['User', 'Group'],
|
||||
required: function (this: IAclEntry) {
|
||||
return this.principalType !== 'public';
|
||||
return this.principalType !== PrincipalType.PUBLIC;
|
||||
},
|
||||
},
|
||||
resourceType: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue