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
18 changes: 17 additions & 1 deletion packages/rocketchat-api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,23 @@ 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()) {
findResult = RocketChat.models.Subscriptions.findByRoomId(params.roomId).fetch()[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not find the room directly? Looking for subscriptions will cause the code to fail on empty rooms.

} else if (params.roomName && params.roomName.trim()) {
findResult = RocketChat.models.Subscriptions.findOneByRoomName(params.roomName);
} 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();

Expand Down
8 changes: 8 additions & 0 deletions packages/rocketchat-lib/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class ModelSubscriptions extends RocketChat.models._Base {
return this.findOne(query);
}

findOneByRoomName(roomName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you use the room directly, this method won't be necessary.

const query = {
name: roomName
};

return this.findOne(query);
}

// FIND
findByUserId(userId, options) {
if (this.useCache) {
Expand Down