Skip to content
Snippets Groups Projects
Commit 2fc7c2bb authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Don’t allow to change type of direct rooms. Add migration

Closes #5808
parent 869ad7fe
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,15 @@ RocketChat.saveRoomType = (rid, roomType, user, sendMessage=true) ->
throw new Meteor.Error 'invalid-room', 'Invalid room', { function: 'RocketChat.saveRoomType' }
if roomType not in ['c', 'p']
throw new Meteor.Error 'error-invalid-room-type', 'error-invalid-room-type', { type: roomType }
throw new Meteor.Error 'error-invalid-room-type', 'error-invalid-room-type', { function: 'RocketChat.saveRoomType', type: roomType }
room = RocketChat.models.Rooms.findOneById(rid);
if not room?
throw new Meteor.Error 'error-invalid-room', 'error-invalid-room', { function: 'RocketChat.saveRoomType', _id: rid }
if room.t is 'd'
throw new Meteor.Error 'error-direct-room', 'Can\'t change type of direct rooms', { function: 'RocketChat.saveRoomType' }
result = RocketChat.models.Rooms.setTypeById(rid, roomType) and RocketChat.models.Subscriptions.updateTypeByRoomId(rid, roomType)
......
RocketChat.Migrations.add({
version: 85,
up() {
const query = {
t: 'p',
usernames: {$size: 2},
u: {$exists: false},
name: {$exists: false}
};
const rooms = RocketChat.models.Rooms.find(query).fetch();
if (rooms.length > 0) {
const rids = rooms.map(room => room._id);
RocketChat.models.Rooms.update({_id: {$in: rids}}, {$set: {t: 'd'}}, {multi: true});
RocketChat.models.Subscriptions.update({rid: {$in: rids}}, {$set: {t: 'd'}}, {multi: true});
}
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment