Skip to content

Commit 4257d32

Browse files
ggazzosampaiodiego
andcommitted
regression(federation): Old federation users (#37102)
Co-authored-by: Diego Sampaio <chinello@gmail.com>
1 parent bda2fa4 commit 4257d32

File tree

19 files changed

+285
-215
lines changed

19 files changed

+285
-215
lines changed

apps/meteor/app/lib/server/functions/createDirectRoom.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ export async function createDirectRoom(
7171

7272
await callbacks.run('beforeCreateDirectRoom', membersUsernames, roomExtraData);
7373

74-
const roomMembers: IUser[] = await Users.findUsersByUsernames(membersUsernames, {
75-
projection: { _id: 1, name: 1, username: 1, settings: 1, customFields: 1 },
76-
}).toArray();
74+
const roomMembers = await Users.findUsersByUsernames(membersUsernames).toArray();
7775
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7876
const sortedMembers = roomMembers.sort((u1, u2) => (u1.name! || u1.username!).localeCompare(u2.name! || u2.username!));
7977

apps/meteor/app/lib/server/methods/addUsersToRoom.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { api } from '@rocket.chat/core-services';
22
import type { IUser } from '@rocket.chat/core-typings';
3-
import { isRoomFederated } from '@rocket.chat/core-typings';
43
import type { ServerMethods } from '@rocket.chat/ddp-client';
54
import { Subscriptions, Users, Rooms } from '@rocket.chat/models';
65
import { Match } from 'meteor/check';
76
import { Meteor } from 'meteor/meteor';
87

9-
import { callbacks } from '../../../../lib/callbacks';
108
import { i18n } from '../../../../server/lib/i18n';
119
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
1210
import { addUserToRoom } from '../functions/addUserToRoom';
@@ -79,12 +77,6 @@ export const addUsersToRoomMethod = async (userId: string, data: { rid: string;
7977
});
8078
}
8179

82-
// Validate each user, then add to room
83-
if (isRoomFederated(room)) {
84-
await callbacks.run('federation.onAddUsersToRoom', { invitees: data.users, inviter: user }, room);
85-
return true;
86-
}
87-
8880
await Promise.all(
8981
data.users.map(async (username) => {
9082
const newUser = await Users.findOneByUsernameIgnoringCase(username);

apps/meteor/ee/server/hooks/federation/index.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,6 @@ callbacks.add(
7070
'native-federation-after-delete-message',
7171
);
7272

73-
callbacks.add(
74-
'federation.onAddUsersToRoom',
75-
async ({ invitees, inviter }, room) => {
76-
if (FederationActions.shouldPerformFederationAction(room)) {
77-
await FederationMatrix.inviteUsersToRoom(
78-
room,
79-
invitees.map((invitee) => (typeof invitee === 'string' ? invitee : invitee.username)).filter((v) => v != null),
80-
inviter,
81-
);
82-
}
83-
},
84-
callbacks.priority.MEDIUM,
85-
'native-federation-on-add-users-to-room ',
86-
);
87-
8873
beforeAddUserToRoom.add(
8974
async ({ user, inviter }, room) => {
9075
if (!user.username || !inviter) {

apps/meteor/lib/callbacks.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
VideoConference,
1212
OEmbedMeta,
1313
OEmbedUrlContent,
14-
Username,
1514
IOmnichannelRoom,
1615
ILivechatTag,
1716
ILivechatTagRecord,
@@ -85,7 +84,6 @@ interface EventLikeCallbackSignatures {
8584
message: IMessage,
8685
params: { user: IUser; reaction: string; shouldReact: boolean; oldMessage: IMessage; room: IRoom },
8786
) => void;
88-
'federation.onAddUsersToRoom': (params: { invitees: IUser[] | Username[]; inviter: IUser }, room: IRoom) => void;
8987
'onJoinVideoConference': (callId: VideoConference['_id'], userId?: IUser['_id']) => Promise<void>;
9088
'usernameSet': () => void;
9189
'beforeJoinRoom': (user: IUser, room: IRoom) => void;

apps/meteor/server/methods/addRoomModerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const addRoomModerator = async (fromUserId: IUser['_id'], rid: IRoom['_id
2424
check(rid, String);
2525
check(userId, String);
2626

27-
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1 } });
27+
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1, federation: 1 } });
2828
if (!room) {
2929
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
3030
method: 'addRoomModerator',

apps/meteor/server/methods/addRoomOwner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const addRoomOwner = async (fromUserId: IUser['_id'], rid: IRoom['_id'],
2424
check(rid, String);
2525
check(userId, String);
2626

27-
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1 } });
27+
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1, federation: 1 } });
2828
if (!room) {
2929
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
3030
method: 'addRoomOwner',

apps/meteor/server/methods/removeRoomModerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const removeRoomModerator = async (fromUserId: IUser['_id'], rid: IRoom['
2323
check(rid, String);
2424
check(userId, String);
2525

26-
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1 } });
26+
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1, federation: 1 } });
2727
if (!room) {
2828
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
2929
method: 'removeRoomModerator',

apps/meteor/server/methods/removeRoomOwner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const removeRoomOwner = async (fromUserId: string, rid: string, userId: s
2222
check(rid, String);
2323
check(userId, String);
2424

25-
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1 } });
25+
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1, federation: 1 } });
2626
if (!room) {
2727
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
2828
method: 'removeRoomOwner',

apps/meteor/tests/end-to-end/api/livechat/14-units.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,8 @@ import { IS_EE } from '../../../e2e/config/constants';
635635
expect(updatedUnit).to.have.property('numDepartments', 1);
636636

637637
const fullDepartment = await getDepartmentById(department._id);
638-
expect(fullDepartment).to.have.property('parentId').that.is.null;
639-
expect(fullDepartment).to.have.property('ancestors').that.is.null;
638+
expect(fullDepartment).to.not.have.property('parentId');
639+
expect(fullDepartment).to.not.have.property('ancestors');
640640
});
641641

642642
it('should fail adding a department into an existing unit that a monitor does not supervise', async () => {
@@ -658,8 +658,8 @@ import { IS_EE } from '../../../e2e/config/constants';
658658
expect(updatedUnit).to.have.property('numDepartments', 1);
659659

660660
const fullDepartment = await getDepartmentById(department._id);
661-
expect(fullDepartment).to.have.property('parentId').that.is.null;
662-
expect(fullDepartment).to.have.property('ancestors').that.is.null;
661+
expect(fullDepartment).to.not.have.property('parentId');
662+
expect(fullDepartment).to.not.have.property('ancestors');
663663
});
664664

665665
it('should succesfully add a department into an existing unit that a monitor supervises', async () => {
@@ -732,8 +732,8 @@ import { IS_EE } from '../../../e2e/config/constants';
732732

733733
const fullDepartment = await getDepartmentById(department._id);
734734
expect(fullDepartment).to.have.property('name', updatedName);
735-
expect(fullDepartment).to.have.property('parentId').that.is.null;
736-
expect(fullDepartment).to.have.property('ancestors').that.is.null;
735+
expect(fullDepartment).to.not.have.property('parentId');
736+
expect(fullDepartment).to.not.have.property('ancestors');
737737
});
738738
});
739739

@@ -872,8 +872,8 @@ import { IS_EE } from '../../../e2e/config/constants';
872872
expect(updatedUnit).to.have.property('numDepartments', 1);
873873

874874
const fullDepartment = await getDepartmentById(testDepartmentId);
875-
expect(fullDepartment).to.have.property('parentId').that.is.null;
876-
expect(fullDepartment).to.have.property('ancestors').that.is.null;
875+
expect(fullDepartment).to.not.have.property('parentId');
876+
expect(fullDepartment).to.not.have.property('ancestors');
877877
});
878878

879879
it('should succesfully add an existing department to a unit as an admin', async () => {
@@ -904,8 +904,8 @@ import { IS_EE } from '../../../e2e/config/constants';
904904
expect(updatedUnit).to.have.property('numDepartments', 1);
905905

906906
const fullDepartment = await getDepartmentById(testDepartmentId);
907-
expect(fullDepartment).to.have.property('parentId').that.is.null;
908-
expect(fullDepartment).to.have.property('ancestors').that.is.null;
907+
expect(fullDepartment).to.not.have.property('parentId');
908+
expect(fullDepartment).to.not.have.property('ancestors');
909909
});
910910

911911
it('should succesfully add an existing department to a unit that a monitor supervises', async () => {

0 commit comments

Comments
 (0)