Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/hooks/abac/beforeAddUserToRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ beforeAddUserToRoom.patch(async (prev, users, room, actor) => {
throw new Error('error-room-is-abac-managed');
}

await Abac.checkUsernamesMatchAttributes(validUsers as string[], room.abacAttributes, room._id);
await Abac.checkUsernamesMatchAttributes(validUsers as string[], room.abacAttributes, room);
});
4 changes: 2 additions & 2 deletions ee/packages/abac/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export class AbacService extends ServiceClass implements IAbacService {
await this.onRoomAttributesChanged(room, updated?.abacAttributes || []);
}

async checkUsernamesMatchAttributes(usernames: string[], attributes: IAbacAttributeDefinition[], objectId: string): Promise<void> {
async checkUsernamesMatchAttributes(usernames: string[], attributes: IAbacAttributeDefinition[], object: IRoom): Promise<void> {
if (!usernames.length || !attributes.length) {
return;
}
Expand All @@ -486,7 +486,7 @@ export class AbacService extends ServiceClass implements IAbacService {

usernames.forEach((username) => {
// TODO: Add room name
void Audit.actionPerformed({ username }, { _id: objectId }, 'system', 'granted-object-access');
void Audit.actionPerformed({ username }, { _id: object._id, name: object.name }, 'system', 'granted-object-access');
});
}

Expand Down
22 changes: 16 additions & 6 deletions ee/packages/abac/src/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,12 +1037,14 @@ describe('AbacService (unit)', () => {
const attributes = [{ key: 'dept', values: ['eng'] }];

it('returns early (no query) when usernames array is empty', async () => {
await expect(service.checkUsernamesMatchAttributes([], attributes as any, 'objectId')).resolves.toBeUndefined();
await expect(
service.checkUsernamesMatchAttributes([], attributes as any, { _id: 'xxxxx', name: 'name' } as any),
).resolves.toBeUndefined();
expect(mockUsersFind).not.toHaveBeenCalled();
});

it('returns early (no query) when attributes array is empty', async () => {
await expect(service.checkUsernamesMatchAttributes(['alice'], [], 'objectId')).resolves.toBeUndefined();
await expect(service.checkUsernamesMatchAttributes(['alice'], [], { _id: 'xxxxx', name: 'name' } as any)).resolves.toBeUndefined();
expect(mockUsersFind).not.toHaveBeenCalled();
});

Expand All @@ -1054,7 +1056,9 @@ describe('AbacService (unit)', () => {
}),
}));

await expect(service.checkUsernamesMatchAttributes(usernames, attributes as any, 'objectId')).resolves.toBeUndefined();
await expect(
service.checkUsernamesMatchAttributes(usernames, attributes as any, { _id: 'xxxxx', name: 'name' } as any),
).resolves.toBeUndefined();

expect(mockUsersFind).toHaveBeenCalledWith(
{
Expand Down Expand Up @@ -1085,7 +1089,9 @@ describe('AbacService (unit)', () => {
}),
}));

await expect(service.checkUsernamesMatchAttributes(usernames, attributes as any, 'objectId')).rejects.toMatchObject({
await expect(
service.checkUsernamesMatchAttributes(usernames, attributes as any, { _id: 'xxxxx', name: 'name' } as any),
).rejects.toMatchObject({
code: 'error-only-compliant-users-can-be-added-to-abac-rooms',
});
});
Expand All @@ -1099,7 +1105,9 @@ describe('AbacService (unit)', () => {
}),
}));

await expect(service.checkUsernamesMatchAttributes(usernames, attributes as any, 'objectId')).resolves.toBeUndefined();
await expect(
service.checkUsernamesMatchAttributes(usernames, attributes as any, { _id: 'xxxxx', name: 'name' } as any),
).resolves.toBeUndefined();

expect(mockCreateAuditServerEvent).toHaveBeenCalledTimes(usernames.length);
const calledUsernames = mockCreateAuditServerEvent.mock.calls.map(([, payload]: any[]) => payload?.subject?.username).filter(Boolean);
Expand All @@ -1116,7 +1124,9 @@ describe('AbacService (unit)', () => {
}),
}));

await expect(service.checkUsernamesMatchAttributes(usernames, attributes as any, 'objectId')).rejects.toMatchObject({
await expect(
service.checkUsernamesMatchAttributes(usernames, attributes as any, { _id: 'xxxxx', name: 'name' } as any),
).rejects.toMatchObject({
code: 'error-only-compliant-users-can-be-added-to-abac-rooms',
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core-services/src/types/IAbacService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface IAbacService {
removeRoomAbacAttribute(rid: string, key: string, actor: AbacActor | undefined): Promise<void>;
addRoomAbacAttributeByKey(rid: string, key: string, values: string[], actor: AbacActor | undefined): Promise<void>;
replaceRoomAbacAttributeByKey(rid: string, key: string, values: string[], actor: AbacActor | undefined): Promise<void>;
checkUsernamesMatchAttributes(usernames: string[], attributes: IAbacAttributeDefinition[], objectId: string): Promise<void>;
checkUsernamesMatchAttributes(usernames: string[], attributes: IAbacAttributeDefinition[], object: IRoom): Promise<void>;
canAccessObject(
room: Pick<IRoom, '_id' | 't' | 'teamId' | 'prid' | 'abacAttributes'>,
user: Pick<IUser, '_id'>,
Expand Down
Loading