Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] /groups.invite not allow a user to invite even with permission #11010

Merged
merged 7 commits into from
Jun 15, 2018
19 changes: 17 additions & 2 deletions packages/rocketchat-api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,27 @@ 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 });
let findResult;
const canAddUserToAnyPrivateGroup = RocketChat.authz.hasPermission(this.userId, 'add-user-to-any-p-room');
const params = this.requestParams();
if (canAddUserToAnyPrivateGroup) {
if ((params.roomId && params.roomId.trim()) || (params.roomName && params.roomName.trim())) {
const idOrName = params.roomId || params.roomName;
findResult = RocketChat.models.Rooms.findOneByIdOrName(idOrName);
} else {
throw new Meteor.Error('error-room-param-not-provided', 'The parameter "roomId" or "roomName" is required');
}
if (!findResult || findResult.t !== 'p') {
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
}
} else {
findResult = findPrivateGroupByIdOrName({ params, userId: this.userId });
}

const user = this.getUserFromParams();

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

This comment was marked as resolved.

});

return RocketChat.API.v1.success({
Expand Down