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

Create groups.addAll endpoint and add activeUsersOnly param. #6505

Merged
merged 2 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rocketchat-api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RocketChat.API.v1.addRoute('channels.addAll', { authRequired: true }, {
const findResult = findChannelById({ roomId: this.bodyParams.roomId });

Meteor.runAsUser(this.userId, () => {
Meteor.call('addAllUserToRoom', findResult._id);
Meteor.call('addAllUserToRoom', findResult._id, this.bodyParams.activeUsersOnly);
});

return RocketChat.API.v1.success({
Expand Down
14 changes: 14 additions & 0 deletions packages/rocketchat-api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ function findPrivateGroupByIdOrName({ roomId, roomName, userId, checkedArchived
return roomSub;
}

RocketChat.API.v1.addRoute('groups.addAll', { authRequired: true }, {
post() {
const findResult = findPrivateGroupByIdOrName({ roomId: this.bodyParams.roomId, userId: this.userId });

Meteor.runAsUser(this.userId, () => {
Meteor.call('addAllUserToRoom', findResult.rid, this.bodyParams.activeUsersOnly);
});

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

RocketChat.API.v1.addRoute('groups.addModerator', { authRequired: true }, {
post() {
const findResult = findPrivateGroupByIdOrName({ roomId: this.bodyParams.roomId, userId: this.userId });
Expand Down
10 changes: 8 additions & 2 deletions server/methods/addAllUserToRoom.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Meteor.methods({
addAllUserToRoom(rid) {
addAllUserToRoom(rid, activeUsersOnly) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about changing this so that it defaults to false making it an optional parameter with a default value? Something like: activeUsersOnly = false

Copy link
Author

Choose a reason for hiding this comment

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

Totally agreed! I'll make the changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the pull requests and being flexible! :)


check (rid, String);
check (activeUsersOnly, Match.Maybe(Boolean));

if (RocketChat.authz.hasRole(this.userId, 'admin') === true) {
const userCount = RocketChat.models.Users.find().count();
Expand All @@ -18,7 +19,12 @@ Meteor.methods({
});
}

const users = RocketChat.models.Users.find().fetch();
const userFilter = {};
if (activeUsersOnly === true) {
userFilter.active = true;
}

const users = RocketChat.models.Users.find(userFilter).fetch();
const now = new Date();
users.forEach(function(user) {
const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id);
Expand Down