Skip to content

Commit bd28882

Browse files
KevLehmanMartinSchoeler
authored andcommitted
fix: Wrong invite error message (#37851)
1 parent 1479924 commit bd28882

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

apps/meteor/app/slashcommands-invite/server/server.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,15 @@ slashCommands.add({
112112
);
113113
} catch (e: unknown) {
114114
if (isMeteorError(e)) {
115-
const details = Array.isArray(e.details) ? e.details.join(', ') : '';
116-
117-
void api.broadcast('notify.ephemeralMessage', userId, message.rid, {
118-
msg: i18n.t(e.message, { lng: settings.get('Language') || 'en', details: `\`${details}\`` }),
119-
});
120-
return;
115+
if (e.error === 'error-only-compliant-users-can-be-added-to-abac-rooms') {
116+
void api.broadcast('notify.ephemeralMessage', userId, message.rid, {
117+
msg: i18n.t(e.error, { lng: settings.get('Language') || 'en' }),
118+
});
119+
} else {
120+
void api.broadcast('notify.ephemeralMessage', userId, message.rid, {
121+
msg: i18n.t(e.message, { lng: settings.get('Language') || 'en' }),
122+
});
123+
}
121124
}
122125

123126
if (isStringError(e)) {

apps/meteor/tests/end-to-end/api/abac.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ const addAbacAttributesToUserDirectly = async (userId: string, abacAttributes: I
15611561
.expect(400)
15621562
.expect((res) => {
15631563
expect(res.body).to.have.property('success', false);
1564-
expect(res.body).to.have.property('error').that.includes('error-usernames-not-matching-abac-attributes');
1564+
expect(res.body).to.have.property('errorType', 'error-only-compliant-users-can-be-added-to-abac-rooms');
15651565
});
15661566
});
15671567

ee/packages/abac/src/errors.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export enum AbacErrorCode {
77
AttributeDefinitionNotFound = 'error-attribute-definition-not-found',
88
RoomNotFound = 'error-room-not-found',
99
CannotConvertDefaultRoomToAbac = 'error-cannot-convert-default-room-to-abac',
10-
UsernamesNotMatchingAbacAttributes = 'error-usernames-not-matching-abac-attributes',
1110
AbacUnsupportedObjectType = 'error-abac-unsupported-object-type',
1211
AbacUnsupportedOperation = 'error-abac-unsupported-operation',
12+
OnlyCompliantCanBeAddedToRoom = 'error-only-compliant-users-can-be-added-to-abac-rooms',
1313
}
1414

1515
export class AbacError extends Error {
@@ -85,3 +85,9 @@ export class AbacUnsupportedOperationError extends AbacError {
8585
super(AbacErrorCode.AbacUnsupportedOperation, details);
8686
}
8787
}
88+
89+
export class OnlyCompliantCanBeAddedToRoomError extends AbacError {
90+
constructor(details?: unknown) {
91+
super(AbacErrorCode.OnlyCompliantCanBeAddedToRoom, details);
92+
}
93+
}

ee/packages/abac/src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MeteorError, Room, ServiceClass } from '@rocket.chat/core-services';
1+
import { Room, ServiceClass } from '@rocket.chat/core-services';
22
import type { AbacActor, IAbacService } from '@rocket.chat/core-services';
33
import { AbacAccessOperation, AbacObjectType } from '@rocket.chat/core-typings';
44
import type {
@@ -25,6 +25,7 @@ import {
2525
AbacInvalidAttributeValuesError,
2626
AbacUnsupportedObjectTypeError,
2727
AbacUnsupportedOperationError,
28+
OnlyCompliantCanBeAddedToRoomError,
2829
} from './errors';
2930
import {
3031
getAbacRoom,
@@ -480,11 +481,7 @@ export class AbacService extends ServiceClass implements IAbacService {
480481
const nonCompliantSet = new Set<string>(nonCompliantUsersFromList);
481482

482483
if (nonCompliantSet.size) {
483-
throw new MeteorError(
484-
'error-usernames-not-matching-abac-attributes',
485-
'Some usernames do not comply with the ABAC attributes for the room',
486-
Array.from(nonCompliantSet),
487-
);
484+
throw new OnlyCompliantCanBeAddedToRoomError();
488485
}
489486

490487
usernames.forEach((username) => {

ee/packages/abac/src/service.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ describe('AbacService (unit)', () => {
10761076
);
10771077
});
10781078

1079-
it('rejects with error-usernames-not-matching-abac-attributes and details for non-compliant users', async () => {
1079+
it('rejects with error-only-compliant-users-can-be-added-to-abac-rooms and details for non-compliant users', async () => {
10801080
const usernames = ['alice', 'bob', 'charlie'];
10811081
const nonCompliantDocs = [{ username: 'bob' }, { username: 'charlie' }];
10821082
mockUsersFind.mockImplementationOnce(() => ({
@@ -1086,9 +1086,7 @@ describe('AbacService (unit)', () => {
10861086
}));
10871087

10881088
await expect(service.checkUsernamesMatchAttributes(usernames, attributes as any, 'objectId')).rejects.toMatchObject({
1089-
error: 'error-usernames-not-matching-abac-attributes',
1090-
message: expect.stringContaining('[error-usernames-not-matching-abac-attributes]'),
1091-
details: expect.arrayContaining(['bob', 'charlie']),
1089+
code: 'error-only-compliant-users-can-be-added-to-abac-rooms',
10921090
});
10931091
});
10941092

@@ -1119,7 +1117,7 @@ describe('AbacService (unit)', () => {
11191117
}));
11201118

11211119
await expect(service.checkUsernamesMatchAttributes(usernames, attributes as any, 'objectId')).rejects.toMatchObject({
1122-
error: 'error-usernames-not-matching-abac-attributes',
1120+
code: 'error-only-compliant-users-can-be-added-to-abac-rooms',
11231121
});
11241122

11251123
expect(mockCreateAuditServerEvent).not.toHaveBeenCalled();

packages/i18n/src/locales/en.i18n.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6355,6 +6355,7 @@
63556355
"error-not-authorized": "Not authorized",
63566356
"error-not-authorized-federation": "Not authorized to access federation",
63576357
"error-office-hours-are-closed": "The office hours are closed.",
6358+
"error-only-compliant-users-can-be-added-to-abac-rooms": "Only compliant users can be added to ABAC rooms.",
63586359
"error-password-in-history": "Entered password has been previously used",
63596360
"error-password-policy-not-met": "Password does not meet the server's policy",
63606361
"error-password-policy-not-met-maxLength": "Password does not meet the server's policy of maximum length (password too long)",
@@ -6381,6 +6382,7 @@
63816382
"error-room-is-not-closed": "Room is not closed",
63826383
"error-room-not-on-hold": "Error! Room is not On Hold",
63836384
"error-room-onHold": "Error! Room is On Hold",
6385+
"error-room-is-abac-managed": "This room is ABAC managed and new users cannot be added",
63846386
"error-adding-monitor": "Error adding monitor",
63856387
"error-saving-sla": "An error ocurred while saving the SLA",
63866388
"error-selected-agent-room-agent-are-same": "The selected agent and the room agent are the same",

0 commit comments

Comments
 (0)