Skip to content

Commit

Permalink
add server methods getRoomNameById
Browse files Browse the repository at this point in the history
  • Loading branch information
Qi Yin committed May 26, 2017
1 parent 3018807 commit 231cdaa
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions server/methods/getRoomNameById.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Meteor.methods({
getRoomNameById(rid) {
check(rid, String);

if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'getRoomNameById'
});
}

const room = RocketChat.models.Rooms.findOneById(rid);

if (room == null) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'getRoomNameById'
});
}

const user = Meteor.user();
if (user && user.username && room.usernames.indexOf(user.username) !== -1) {
return room.name;
}

if (room.t !== 'c' || RocketChat.authz.hasPermission(Meteor.userId(), 'view-c-room') !== true) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'getRoomNameById'
});
}

return room.name;
}
});

0 comments on commit 231cdaa

Please sign in to comment.