mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-10-22 01:53:33 +00:00
🐛 fix: move $bitsAllSet filter out of remote-agent aggregation
`enrichRemoteAgentPrincipals` used `$bitsAllSet` inside an aggregation `$match`, which Azure Cosmos DB for MongoDB does not implement. Project `permBits` through the pipeline and filter for `PermissionBits.SHARE` in application code. The extra documents fetched are bounded by ACL entries on a single agent resource, so the cost is negligible. Refs #12729.
This commit is contained in:
parent
da5f6a8b2f
commit
858f0381e5
1 changed files with 11 additions and 1 deletions
|
|
@ -47,13 +47,18 @@ export async function enrichRemoteAgentPrincipals(
|
|||
? Types.ObjectId.createFromHexString(resourceId)
|
||||
: resourceId;
|
||||
|
||||
/**
|
||||
* Filter `permBits` application-side (not via `$bitsAllSet`) for compatibility
|
||||
* with MongoDB forks (e.g. Azure Cosmos DB for MongoDB) that do not implement
|
||||
* the `$bitsAllSet` query operator. Entry count is bounded by ACL entries on a
|
||||
* single agent, so the extra documents fetched are negligible.
|
||||
*/
|
||||
const agentOwnerEntries = await deps.aggregateAclEntries([
|
||||
{
|
||||
$match: {
|
||||
resourceType: ResourceType.AGENT,
|
||||
resourceId: resourceObjectId,
|
||||
principalType: PrincipalType.USER,
|
||||
permBits: { $bitsAllSet: PermissionBits.SHARE },
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -67,6 +72,7 @@ export async function enrichRemoteAgentPrincipals(
|
|||
{
|
||||
$project: {
|
||||
principalId: 1,
|
||||
permBits: 1,
|
||||
userInfo: { $arrayElemAt: ['$userInfo', 0] },
|
||||
},
|
||||
},
|
||||
|
|
@ -76,6 +82,10 @@ export async function enrichRemoteAgentPrincipals(
|
|||
const entriesToBackfill: Types.ObjectId[] = [];
|
||||
|
||||
for (const entry of agentOwnerEntries) {
|
||||
const permBits = entry.permBits as number;
|
||||
if ((permBits & PermissionBits.SHARE) !== PermissionBits.SHARE) {
|
||||
continue;
|
||||
}
|
||||
if (!entry.userInfo) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue