Skip to content

Commit

Permalink
[FIX] /groups.invite not allow a user to invite even with permission (#…
Browse files Browse the repository at this point in the history
…11010)

[FIX] /groups.invite not allow a user to invite even with permission
  • Loading branch information
MarcosSpessatto authored and ggazzo committed Jun 15, 2018
1 parent 873ae7d commit 85b662b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/rocketchat-api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,24 @@ RocketChat.API.v1.addRoute('groups.info', { authRequired: true }, {

RocketChat.API.v1.addRoute('groups.invite', { authRequired: true }, {
post() {
const findResult = findPrivateGroupByIdOrName({ params: this.requestParams(), userId: this.userId });
const { roomId = '', roomName = '' } = this.requestParams();
const idOrName = roomId || roomName;
if (!idOrName.trim()) {
throw new Meteor.Error('error-room-param-not-provided', 'The parameter "roomId" or "roomName" is required');
}

const user = this.getUserFromParams();
const { _id: rid, t: type } = RocketChat.models.Rooms.findOneByIdOrName(idOrName) || {};

Meteor.runAsUser(this.userId, () => {
Meteor.call('addUserToRoom', { rid: findResult.rid, username: user.username });
});
if (!rid || type !== 'p') {
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
}

const { username } = this.getUserFromParams();

Meteor.runAsUser(this.userId, () => Meteor.call('addUserToRoom', { rid, username }));

return RocketChat.API.v1.success({
group: RocketChat.models.Rooms.findOneById(findResult.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude })
group: RocketChat.models.Rooms.findOneById(rid, { fields: RocketChat.API.v1.defaultFieldsToExclude })
});
}
});
Expand Down

0 comments on commit 85b662b

Please sign in to comment.