Regression: Add support to filter on `teams.listRooms` endpoint (#21327)

pull/21292/head^2
Matheus Barbosa Silva 5 years ago committed by GitHub
parent 5e2bc2f095
commit b10da0bae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/api/server/v1/teams.ts
  2. 7
      app/models/server/raw/Rooms.js
  3. 2
      server/sdk/types/ITeamService.ts
  4. 6
      server/services/team/service.ts

@ -128,6 +128,7 @@ API.v1.addRoute('teams.listRooms', { authRequired: true }, {
get() {
const { teamId } = this.queryParams;
const { offset, count } = this.getPaginationItems();
const { query } = this.parseJsonQuery();
const allowPrivateTeam = hasPermission(this.userId, 'view-all-teams');
@ -136,7 +137,7 @@ API.v1.addRoute('teams.listRooms', { authRequired: true }, {
getAllRooms = true;
}
const { records, total } = Promise.await(Team.listRooms(this.userId, teamId, getAllRooms, allowPrivateTeam, { offset, count }));
const { records, total } = Promise.await(Team.listRooms(this.userId, teamId, getAllRooms, allowPrivateTeam, { offset, count }, { query }));
return API.v1.success({
rooms: records,

@ -118,15 +118,16 @@ export class RoomsRaw extends BaseRaw {
return this.find(query, options);
}
findByTeamId(teamId, options = {}) {
const query = {
findByTeamId(teamId, options = {}, query = {}) {
const myQuery = {
...query,
teamId,
teamMain: {
$exists: false,
},
};
return this.find(query, options);
return this.find(myQuery, options);
}
findByTeamIdAndRoomsId(teamId, rids, options = {}) {

@ -44,7 +44,7 @@ export interface ITeamService {
addRoom(uid: string, rid: string, teamId: string, isDefault: boolean): Promise<IRoom>;
addRooms(uid: string, rooms: Array<string>, teamId: string): Promise<Array<IRoom>>;
removeRoom(uid: string, rid: string, teamId: string, canRemoveAnyRoom: boolean): Promise<IRoom>;
listRooms(uid: string, teamId: string, getAllRooms: boolean, allowPrivateTeam: boolean, pagination: IPaginationOptions): Promise<IRecordsWithTotal<IRoom>>;
listRooms(uid: string, teamId: string, getAllRooms: boolean, allowPrivateTeam: boolean, pagination: IPaginationOptions, queryOptions: IQueryOptions<IRoom>): Promise<IRecordsWithTotal<IRoom>>;
listRoomsOfUser(uid: string, teamId: string, userId: string, allowPrivateTeam: boolean, pagination: IPaginationOptions): Promise<IRecordsWithTotal<IRoom>>;
updateRoom(uid: string, rid: string, isDefault: boolean, canUpdateAnyRoom: boolean): Promise<IRoom>;
list(uid: string, paginationOptions?: IPaginationOptions, queryOptions?: IQueryOptions<ITeam>): Promise<IRecordsWithTotal<ITeam>>;

@ -383,7 +383,7 @@ export class TeamService extends ServiceClass implements ITeamService {
};
}
async listRooms(uid: string, teamId: string, getAllRooms: boolean, allowPrivateTeam: boolean, { offset: skip, count: limit }: IPaginationOptions = { offset: 0, count: 50 }): Promise<IRecordsWithTotal<IRoom>> {
async listRooms(uid: string, teamId: string, getAllRooms: boolean, allowPrivateTeam: boolean, { offset: skip, count: limit }: IPaginationOptions = { offset: 0, count: 50 }, { query }: IQueryOptions<IRoom>): Promise<IRecordsWithTotal<IRoom>> {
if (!teamId) {
throw new Error('missing-teamId');
}
@ -396,13 +396,13 @@ export class TeamService extends ServiceClass implements ITeamService {
throw new Error('user-not-on-private-team');
}
if (getAllRooms) {
const teamRoomsCursor = this.RoomsModel.findByTeamId(teamId, { skip, limit });
const teamRoomsCursor = this.RoomsModel.findByTeamId(teamId, { skip, limit }, query);
return {
total: await teamRoomsCursor.count(),
records: await teamRoomsCursor.toArray(),
};
}
const teamRooms = await this.RoomsModel.findByTeamId(teamId, { projection: { _id: 1, t: 1 } }).toArray();
const teamRooms = await this.RoomsModel.findByTeamId(teamId, { skip, limit, projection: { _id: 1, t: 1 } }, query).toArray();
const privateTeamRoomIds = teamRooms.filter((room) => room.t === 'p').map((room) => room._id);
const publicTeamRoomIds = teamRooms.filter((room) => room.t === 'c').map((room) => room._id);

Loading…
Cancel
Save