Skip to content
Snippets Groups Projects
Commit 9f219dd8 authored by Nathan Marcos's avatar Nathan Marcos
Browse files

Create groups.addAll endpoint and add activeUsersOnly param.

parent 9508f2cb
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ RocketChat.API.v1.addRoute('channels.addAll', { authRequired: true }, { ...@@ -22,7 +22,7 @@ RocketChat.API.v1.addRoute('channels.addAll', { authRequired: true }, {
const findResult = findChannelById({ roomId: this.bodyParams.roomId }); const findResult = findChannelById({ roomId: this.bodyParams.roomId });
Meteor.runAsUser(this.userId, () => { Meteor.runAsUser(this.userId, () => {
Meteor.call('addAllUserToRoom', findResult._id); Meteor.call('addAllUserToRoom', findResult._id, this.bodyParams.activeUsersOnly);
}); });
return RocketChat.API.v1.success({ return RocketChat.API.v1.success({
......
...@@ -22,6 +22,20 @@ function findPrivateGroupByIdOrName({ roomId, roomName, userId, checkedArchived ...@@ -22,6 +22,20 @@ function findPrivateGroupByIdOrName({ roomId, roomName, userId, checkedArchived
return roomSub; 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 }, { RocketChat.API.v1.addRoute('groups.addModerator', { authRequired: true }, {
post() { post() {
const findResult = findPrivateGroupByIdOrName({ roomId: this.bodyParams.roomId, userId: this.userId }); const findResult = findPrivateGroupByIdOrName({ roomId: this.bodyParams.roomId, userId: this.userId });
......
Meteor.methods({ Meteor.methods({
addAllUserToRoom(rid) { addAllUserToRoom(rid, activeUsersOnly) {
check (rid, String); check (rid, String);
check (activeUsersOnly, Match.Maybe(Boolean));
if (RocketChat.authz.hasRole(this.userId, 'admin') === true) { if (RocketChat.authz.hasRole(this.userId, 'admin') === true) {
const userCount = RocketChat.models.Users.find().count(); const userCount = RocketChat.models.Users.find().count();
...@@ -18,7 +19,12 @@ Meteor.methods({ ...@@ -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(); const now = new Date();
users.forEach(function(user) { users.forEach(function(user) {
const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id); const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment