From 508b8ee7e8ce8a1c51370cc15d078d7e3c9fcb92 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Mon, 1 Dec 2025 10:00:33 -0600 Subject: [PATCH 1/2] add name to object audit --- ee/packages/abac/src/index.ts | 84 +++++++++++-------- .../src/ServerAudit/IAuditServerAbacAction.ts | 2 +- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/ee/packages/abac/src/index.ts b/ee/packages/abac/src/index.ts index 6d3c236e6a9db..f34e9fbde4fee 100644 --- a/ee/packages/abac/src/index.ts +++ b/ee/packages/abac/src/index.ts @@ -283,13 +283,11 @@ export class AbacService extends ServiceClass implements IAbacService { } async setRoomAbacAttributes(rid: string, attributes: Record, actor: AbacActor): Promise { - const room = await Rooms.findOneByIdAndType>( - rid, - 'p', - { - projection: { abacAttributes: 1, t: 1, teamMain: 1, teamDefault: 1, default: 1 }, - }, - ); + const room = await Rooms.findOneByIdAndType< + Pick + >(rid, 'p', { + projection: { abacAttributes: 1, t: 1, teamMain: 1, teamDefault: 1, default: 1, name: 1 }, + }); if (!room) { throw new Error('error-room-not-found'); } @@ -299,7 +297,7 @@ export class AbacService extends ServiceClass implements IAbacService { if (!Object.keys(attributes).length && room.abacAttributes?.length) { await Rooms.unsetAbacAttributesById(rid); - void Audit.objectAttributesRemoved({ _id: room._id }, room.abacAttributes, actor); + void Audit.objectAttributesRemoved({ _id: room._id, name: room.name }, room.abacAttributes, actor); return; } @@ -308,7 +306,7 @@ export class AbacService extends ServiceClass implements IAbacService { await this.ensureAttributeDefinitionsExist(normalized); const updated = await Rooms.setAbacAttributesById(rid, normalized); - void Audit.objectAttributeChanged({ _id: room._id }, room.abacAttributes || [], normalized, 'updated', actor); + void Audit.objectAttributeChanged({ _id: room._id, name: room.name }, room.abacAttributes || [], normalized, 'updated', actor); const previous: IAbacAttributeDefinition[] = room.abacAttributes || []; if (this.didAttributesChange(previous, normalized)) { @@ -387,13 +385,11 @@ export class AbacService extends ServiceClass implements IAbacService { } async updateRoomAbacAttributeValues(rid: string, key: string, values: string[], actor: AbacActor): Promise { - const room = await Rooms.findOneByIdAndType>( - rid, - 'p', - { - projection: { abacAttributes: 1, t: 1, teamMain: 1, teamDefault: 1, default: 1 }, - }, - ); + const room = await Rooms.findOneByIdAndType< + Pick + >(rid, 'p', { + projection: { abacAttributes: 1, t: 1, teamMain: 1, teamDefault: 1, default: 1, name: 1 }, + }); if (!room) { throw new Error('error-room-not-found'); } @@ -414,7 +410,13 @@ export class AbacService extends ServiceClass implements IAbacService { if (isNewKey) { await Rooms.updateSingleAbacAttributeValuesById(rid, key, values); - void Audit.objectAttributeChanged({ _id: room._id }, room.abacAttributes || [], [{ key, values }], 'key-added', actor); + void Audit.objectAttributeChanged( + { _id: room._id, name: room.name }, + room.abacAttributes || [], + [{ key, values }], + 'key-added', + actor, + ); const next = [...previous, { key, values }]; await this.onRoomAttributesChanged(room, next); @@ -442,8 +444,8 @@ export class AbacService extends ServiceClass implements IAbacService { } async removeRoomAbacAttribute(rid: string, key: string, actor: AbacActor): Promise { - const room = await Rooms.findOneByIdAndType>(rid, 'p', { - projection: { abacAttributes: 1, default: 1, teamDefault: 1 }, + const room = await Rooms.findOneByIdAndType>(rid, 'p', { + projection: { abacAttributes: 1, default: 1, teamDefault: 1, name: 1 }, }); if (!room) { throw new Error('error-room-not-found'); @@ -469,7 +471,7 @@ export class AbacService extends ServiceClass implements IAbacService { await Rooms.removeAbacAttributeByRoomIdAndKey(rid, key); void Audit.objectAttributeRemoved( - { _id: room._id }, + { _id: room._id, name: room.name }, previous, previous.filter((a) => a.key !== key), 'key-removed', @@ -480,13 +482,11 @@ export class AbacService extends ServiceClass implements IAbacService { async addRoomAbacAttributeByKey(rid: string, key: string, values: string[], actor: AbacActor): Promise { await this.ensureAttributeDefinitionsExist([{ key, values }]); - const room = await Rooms.findOneByIdAndType>( - rid, - 'p', - { - projection: { abacAttributes: 1, t: 1, teamMain: 1, teamDefault: 1, default: 1 }, - }, - ); + const room = await Rooms.findOneByIdAndType< + Pick + >(rid, 'p', { + projection: { abacAttributes: 1, t: 1, teamMain: 1, teamDefault: 1, default: 1, name: 1 }, + }); if (!room) { throw new Error('error-room-not-found'); } @@ -507,7 +507,7 @@ export class AbacService extends ServiceClass implements IAbacService { const updated = await Rooms.insertAbacAttributeIfNotExistsById(rid, key, values); const next = updated?.abacAttributes || [...previous, { key, values }]; - void Audit.objectAttributeChanged({ _id: room._id }, previous, next, 'key-added', actor); + void Audit.objectAttributeChanged({ _id: room._id, name: room.name }, previous, next, 'key-added', actor); await this.onRoomAttributesChanged(room, next); } @@ -515,13 +515,11 @@ export class AbacService extends ServiceClass implements IAbacService { async replaceRoomAbacAttributeByKey(rid: string, key: string, values: string[], actor: AbacActor): Promise { await this.ensureAttributeDefinitionsExist([{ key, values }]); - const room = await Rooms.findOneByIdAndType>( - rid, - 'p', - { - projection: { abacAttributes: 1, t: 1, teamMain: 1, teamDefault: 1, default: 1 }, - }, - ); + const room = await Rooms.findOneByIdAndType< + Pick + >(rid, 'p', { + projection: { abacAttributes: 1, t: 1, teamMain: 1, teamDefault: 1, default: 1, name: 1 }, + }); if (!room) { throw new Error('error-room-not-found'); } @@ -536,7 +534,13 @@ export class AbacService extends ServiceClass implements IAbacService { const updated = await Rooms.updateAbacAttributeValuesArrayFilteredById(rid, key, values); const prevValues = room.abacAttributes?.find((a) => a.key === key)?.values ?? []; - void Audit.objectAttributeChanged({ _id: room._id }, room.abacAttributes || [], updated?.abacAttributes || [], 'key-updated', actor); + void Audit.objectAttributeChanged( + { _id: room._id, name: room.name }, + room.abacAttributes || [], + updated?.abacAttributes || [], + 'key-updated', + actor, + ); if (this.wereAttributeValuesAdded(prevValues, values)) { await this.onRoomAttributesChanged(room, updated?.abacAttributes || []); } @@ -549,7 +553,13 @@ export class AbacService extends ServiceClass implements IAbacService { } const updated = await Rooms.insertAbacAttributeIfNotExistsById(rid, key, values); - void Audit.objectAttributeChanged({ _id: room._id }, room.abacAttributes || [], updated?.abacAttributes || [], 'key-added', actor); + void Audit.objectAttributeChanged( + { _id: room._id, name: room.name }, + room.abacAttributes || [], + updated?.abacAttributes || [], + 'key-added', + actor, + ); await this.onRoomAttributesChanged(room, updated?.abacAttributes || []); } diff --git a/packages/core-typings/src/ServerAudit/IAuditServerAbacAction.ts b/packages/core-typings/src/ServerAudit/IAuditServerAbacAction.ts index fca23a0764699..e8f97f7606b22 100644 --- a/packages/core-typings/src/ServerAudit/IAuditServerAbacAction.ts +++ b/packages/core-typings/src/ServerAudit/IAuditServerAbacAction.ts @@ -1,7 +1,7 @@ import type { IUser, IRoom, IAuditServerEventType, IAbacAttributeDefinition, IServerEvents } from '..'; export type MinimalUser = Pick; -export type MinimalRoom = Pick; +export type MinimalRoom = Pick; export type AbacAuditReason = 'ldap-sync' | 'room-attributes-change' | 'system' | 'api' | 'realtime-policy-eval'; From 18564ca50a3bf85831a4341296cc96e3826437da Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Mon, 1 Dec 2025 11:48:26 -0600 Subject: [PATCH 2/2] fix --- ee/packages/abac/src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ee/packages/abac/src/index.ts b/ee/packages/abac/src/index.ts index f34e9fbde4fee..1fc606ac7f327 100644 --- a/ee/packages/abac/src/index.ts +++ b/ee/packages/abac/src/index.ts @@ -430,7 +430,13 @@ export class AbacService extends ServiceClass implements IAbacService { } await Rooms.updateAbacAttributeValuesArrayFilteredById(rid, key, values); - void Audit.objectAttributeChanged({ _id: room._id }, room.abacAttributes || [], [{ key, values }], 'key-updated', actor); + void Audit.objectAttributeChanged( + { _id: room._id, name: room.name }, + room.abacAttributes || [], + [{ key, values }], + 'key-updated', + actor, + ); if (this.wereAttributeValuesAdded(prevValues, values)) { const next = previous.map((a, i) => (i === existingIndex ? { key, values } : a));