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

[NEW] Allows admin to list all groups with API #7565

Merged
merged 13 commits into from
Aug 24, 2017
27 changes: 27 additions & 0 deletions packages/rocketchat-api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,33 @@ RocketChat.API.v1.addRoute('groups.list', { authRequired: true }, {
}
});


RocketChat.API.v1.addRoute('groups.listAll', { authRequired: true }, {
get() {
if (!RocketChat.authz.hasPermission(this.userId, 'view-room-administration')) {
return RocketChat.API.v1.unauthorized();
}
const { offset, count } = this.getPaginationItems();
const { sort, fields } = this.parseJsonQuery();
let rooms = RocketChat.models.Rooms.findByType('p').fetch();
const totalCount = rooms.length;

rooms = RocketChat.models.Rooms.processQueryOptionsOnResult(rooms, {
sort: sort ? sort : { name: 1 },
skip: offset,
limit: count,
fields: Object.assign({}, fields, RocketChat.API.v1.defaultFieldsToExclude)
});

return RocketChat.API.v1.success({
groups: rooms,
offset,
count: rooms.length,
total: totalCount
});
}
});

RocketChat.API.v1.addRoute('groups.members', { authRequired: true }, {
get() {
const findResult = findPrivateGroupByIdOrName({ params: this.requestParams(), userId: this.userId });
Expand Down