mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
feat: enhance agent permissions migration with DocumentDB compatibility and add dry-run script
This commit is contained in:
parent
c62a23fafc
commit
f9994d1547
2 changed files with 23 additions and 16 deletions
|
|
@ -32,32 +32,36 @@ async function migrateAgentPermissionsEnhanced({ dryRun = true, batchSize = 100
|
|||
|
||||
logger.info(`Found ${globalAgentIds.size} agents in global project`);
|
||||
|
||||
// Find agents without ACL entries
|
||||
// Find agents without ACL entries using DocumentDB-compatible approach
|
||||
const agentsToMigrate = await Agent.aggregate([
|
||||
{
|
||||
$lookup: {
|
||||
from: 'aclentries',
|
||||
let: { agentId: '$_id' },
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$resourceType', 'agent'] },
|
||||
{ $eq: ['$resourceId', '$$agentId'] },
|
||||
{ $eq: ['$principalType', 'user'] },
|
||||
],
|
||||
},
|
||||
localField: '_id',
|
||||
foreignField: 'resourceId',
|
||||
as: 'aclEntries',
|
||||
},
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
userAclEntries: {
|
||||
$filter: {
|
||||
input: '$aclEntries',
|
||||
as: 'aclEntry',
|
||||
cond: {
|
||||
$and: [
|
||||
{ $eq: ['$$aclEntry.resourceType', 'agent'] },
|
||||
{ $eq: ['$$aclEntry.principalType', 'user'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'aclEntries',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
author: { $exists: true, $ne: null },
|
||||
$expr: { $eq: [{ $size: '$aclEntries' }, 0] },
|
||||
userAclEntries: { $size: 0 },
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -71,7 +71,10 @@
|
|||
"b:test:api": "cd api && bun run b:test",
|
||||
"b:balance": "bun config/add-balance.js",
|
||||
"b:list-balances": "bun config/list-balances.js",
|
||||
"reset-terms": "node config/reset-terms.js"
|
||||
"reset-terms": "node config/reset-terms.js",
|
||||
"migrate:agent-permissions:dry-run": "node config/migrate-agent-permissions.js --dry-run",
|
||||
"migrate:agent-permissions": "node config/migrate-agent-permissions.js",
|
||||
"migrate:agent-permissions:batch": "node config/migrate-agent-permissions.js --batch-size=50"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue