Skip to content
Closed
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
8 changes: 8 additions & 0 deletions app/models/server/models/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,14 @@ export class Messages extends Base {
return this.createWithTypeRoomIdMessageAndUser('subscription-role-removed', roomId, message, user, extraData);
}

createRoomAddedToTeamWithRoomIdAndUser(roomId, message, user, extraData) {
return this.createWithTypeRoomIdMessageAndUser('room_added_to_team', roomId, message, user, extraData);
}

createRoomRemovedFromTeamWithRoomIdAndUser(roomId, message, user, extraData) {
return this.createWithTypeRoomIdMessageAndUser('room_removed_from_team', roomId, message, user, extraData);
}

// REMOVE
removeById(_id) {
const query = { _id };
Expand Down
28 changes: 28 additions & 0 deletions client/startup/messageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,32 @@ Meteor.startup(() => {
};
},
});

MessageTypes.registerType({
id: 'room_added_to_team',
system: true,
message: 'room_added_to_team',
data(message: IMessage) {
return {
// eslint-disable-next-line @typescript-eslint/camelcase
user_by: message.u && message.u.username,
// eslint-disable-next-line @typescript-eslint/camelcase
room_names: escapeHTML(message.msg || `(${t('None').toLowerCase()})`),
};
},
});

MessageTypes.registerType({
id: 'room_removed_from_team',
system: true,
message: 'room_removed_from_team',
data(message: IMessage) {
return {
// eslint-disable-next-line @typescript-eslint/camelcase
user_by: message.u && message.u.username,
// eslint-disable-next-line @typescript-eslint/camelcase
room_name: escapeHTML(message.msg || `(${t('None').toLowerCase()})`),
};
},
});
});
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3518,11 +3518,13 @@
"Room_archivation_state_false": "Active",
"Room_archivation_state_true": "Archived",
"Room_archived": "Room archived",
"room_added_to_team": "Room(s): <em>__room_names__</em> added to the team by <em>__user_by__<em/>",
"room_changed_announcement": "Room announcement changed to: <em>__room_announcement__</em> by <em>__user_by__</em>",
"room_changed_avatar": "Room avatar changed by <em>__user_by__</em>",
"room_changed_description": "Room description changed to: <em>__room_description__</em> by <em>__user_by__</em>",
"room_changed_privacy": "Room type changed to: <em>__room_type__</em> by <em>__user_by__</em>",
"room_changed_topic": "Room topic changed to: <em>__room_topic__</em> by <em>__user_by__</em>",
"room_removed_from_team": "Room: <em>__room_name__</em> was removed from the team by <em>__user_by__<em/>",
"Room_default_change_to_private_will_be_default_no_more": "This is a default channel and changing it to a private group will cause it to no longer be a default channel. Do you want to proceed?",
"Room_description_changed_successfully": "Room description changed successfully",
"Room_Edit": "Room Edit",
Expand Down
12 changes: 8 additions & 4 deletions server/services/team/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { addUserToRoom } from '../../../app/lib/server/functions/addUserToRoom';
import { removeUserFromRoom } from '../../../app/lib/server/functions/removeUserFromRoom';
import { getSubscribedRoomsForUserWithDetails } from '../../../app/lib/server/functions/getRoomsWithSingleOwner';
import type { InsertionModel } from '../../../app/models/server/raw/BaseRaw';
import { Messages } from '../../../app/models/server';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this would add make the service dependant on Meteor's base models, which is something we're trying to avoid. Can we replicate the changes on the Messages raw model instead? (Even if we need to duplicate some functions) 👀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing that but there's one function (insertOrUpsert) that is hard to duplicate in BaseRaw...

import { MessagesRaw } from '../../../app/models/server/raw/Messages';
import { RoomsRaw } from '../../../app/models/server/raw/Rooms';
import { SubscriptionsRaw } from '../../../app/models/server/raw/Subscriptions';
Expand Down Expand Up @@ -312,7 +313,7 @@ export class TeamService extends ServiceClass implements ITeamService {
throw new Error('missing-userId');
}

const team = await this.TeamModel.findOneById(teamId, { projection: { _id: 1 } });
const team = await this.TeamModel.findOne(teamId, { projection: { _id: 1, roomId: 1 } });
if (!team) {
throw new Error('invalid-team');
}
Expand All @@ -322,6 +323,7 @@ export class TeamService extends ServiceClass implements ITeamService {
const user = await this.Users.findOneById(uid);
const rids = rooms.filter((rid) => rid && typeof rid === 'string');
const validRooms = await this.RoomsModel.findManyByRoomIds(rids).toArray();
const roomNames = [];
if (validRooms.length < rids.length) {
throw new Error('invalid-room');
}
Expand All @@ -342,11 +344,12 @@ export class TeamService extends ServiceClass implements ITeamService {
if (!await this.SubscriptionsModel.isUserInRole(uid, 'owner', room._id)) {
throw new Error('error-no-owner-channel');
}

roomNames.push(room.name);
room.teamId = teamId;
}

this.RoomsModel.setTeamByIds(rids, teamId);
Messages.createRoomAddedToTeamWithRoomIdAndUser(team.roomId, roomNames.join(), user, {});
return validRooms;
}

Expand All @@ -366,15 +369,15 @@ export class TeamService extends ServiceClass implements ITeamService {
throw new Error('invalid-room');
}

const user = await this.Users.findOneById(uid);
if (!canRemoveAnyRoom) {
const user = await this.Users.findOneById(uid);
const canSeeRoom = await canAccessRoom(room, user);
if (!canSeeRoom) {
throw new Error('invalid-room');
}
}

const team = await this.TeamModel.findOneById(teamId, { projection: { _id: 1 } });
const team = await this.TeamModel.findOneById(teamId, { projection: { _id: 1, roomId: 1 } });
if (!team) {
throw new Error('invalid-team');
}
Expand All @@ -386,6 +389,7 @@ export class TeamService extends ServiceClass implements ITeamService {
delete room.teamId;
delete room.teamDefault;
this.RoomsModel.unsetTeamById(room._id);
Messages.createRoomRemovedFromTeamWithRoomIdAndUser(team.roomId, room.name, user, {});
return {
...room,
};
Expand Down