mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 15:02:02 +00:00
🚥 fix: Preserve Insights With Guarded ACL Role Updates (#16170)
* fix: preserve Insights with guarded ACL role updates * test: settle ACL index builds before opening the transaction * fix: replace ACL mask partitions with single-operator bit writes * style: drop the now-unused RoleBits import * fix: make ACL role replacement one atomic guarded write * fix: export the permission write retry ceiling * fix: retry ACL mutations per document and preserve atomic permissions --------- Co-authored-by: Lia <lia@librechat.ai>
This commit is contained in:
parent
cae9afd807
commit
1e2142e52a
12 changed files with 897 additions and 39 deletions
|
|
@ -173,6 +173,7 @@ const updateResourcePermissions = async (req, res) => {
|
|||
const results = await bulkUpdateResourcePermissions({
|
||||
resourceType,
|
||||
resourceId,
|
||||
maxWriteAttempts: req.config?.config?.permissions?.maxWriteAttempts,
|
||||
updatedPrincipals: validatedPrincipals,
|
||||
revokedPrincipals,
|
||||
grantedBy: userId,
|
||||
|
|
|
|||
|
|
@ -339,8 +339,12 @@ describe('PermissionsController', () => {
|
|||
});
|
||||
const res = createMockRes();
|
||||
|
||||
req.config = { config: { permissions: { maxWriteAttempts: 7 } } };
|
||||
await updateResourcePermissions(req, res);
|
||||
|
||||
expect(mockBulkUpdateResourcePermissions).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ maxWriteAttempts: 7 }),
|
||||
);
|
||||
expect(mockRecordAuditEntry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: 'permission.insights_assigned',
|
||||
|
|
|
|||
|
|
@ -1062,9 +1062,9 @@ describe('PermissionService', () => {
|
|||
);
|
||||
}
|
||||
|
||||
const originalBulkWriteAclEntries = db.bulkWriteAclEntries;
|
||||
const originalBulkWriteAclEntries = AclEntry.bulkWrite.bind(AclEntry);
|
||||
const bulkWriteSpy = jest
|
||||
.spyOn(db, 'bulkWriteAclEntries')
|
||||
.spyOn(AclEntry, 'bulkWrite')
|
||||
.mockImplementationOnce(async (...args) => {
|
||||
await AclEntry.updateOne(
|
||||
{
|
||||
|
|
@ -1091,6 +1091,7 @@ describe('PermissionService', () => {
|
|||
],
|
||||
grantedBy: grantedById,
|
||||
});
|
||||
expect(bulkWriteSpy).toHaveBeenCalled();
|
||||
} finally {
|
||||
bulkWriteSpy.mockRestore();
|
||||
}
|
||||
|
|
@ -1107,9 +1108,9 @@ describe('PermissionService', () => {
|
|||
);
|
||||
|
||||
test('removes a stale-read upsert after a concurrent deletion and audit failure', async () => {
|
||||
const originalBulkWriteAclEntries = db.bulkWriteAclEntries;
|
||||
const originalBulkWriteAclEntries = AclEntry.bulkWrite.bind(AclEntry);
|
||||
const bulkWriteSpy = jest
|
||||
.spyOn(db, 'bulkWriteAclEntries')
|
||||
.spyOn(AclEntry, 'bulkWrite')
|
||||
.mockImplementationOnce(async (...args) => {
|
||||
await AclEntry.deleteOne({
|
||||
principalType: PrincipalType.USER,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue