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: "Discussions" filter is prioritized in admin "Rooms" page #28426

Merged
merged 33 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d9d777d
refactor code and update query
heitortanoue Mar 15, 2023
40b3d50
fix lint
heitortanoue Mar 15, 2023
2e14495
Merge branch 'develop' into fix/admin-rooms-checkboxes
heitortanoue Mar 16, 2023
7381f08
fix test that was failing
heitortanoue Mar 16, 2023
216dc8d
Merge branch 'develop' into fix/admin-rooms-checkboxes
gabriellsh Mar 17, 2023
af55103
add some tests, remove consolelog
heitortanoue Mar 17, 2023
0191485
Merge branch 'fix/admin-rooms-checkboxes' of https://github.com/Rocke…
heitortanoue Mar 17, 2023
57cbcad
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
heitortanoue Mar 20, 2023
d4e9cd0
Merge branch 'develop' into fix/admin-rooms-checkboxes
heitortanoue Mar 20, 2023
8d5c701
Merge branch 'develop' into fix/admin-rooms-checkboxes
heitortanoue Mar 20, 2023
56de9db
Merge branch 'develop' into fix/admin-rooms-checkboxes
heitortanoue Mar 21, 2023
0375341
Merge branch 'develop' into fix/admin-rooms-checkboxes
heitortanoue Mar 22, 2023
f48e192
change rooms.ts v1
heitortanoue Mar 22, 2023
d105433
delete rooms.js (after new rooms.ts)
heitortanoue Mar 22, 2023
2259cc7
fix types findAdminRooms
heitortanoue Mar 22, 2023
9f6e96f
fix types parameter on v1 get
heitortanoue Mar 23, 2023
727f673
fix teams and discussion filter
heitortanoue Mar 24, 2023
1b89a78
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
heitortanoue Mar 27, 2023
77a522c
fix tests
heitortanoue Mar 27, 2023
07588e0
Improve readability and add discussions to default filter
matheusbsilva137 Mar 29, 2023
777b554
Merge branch 'develop' into fix/admin-rooms-checkboxes
matheusbsilva137 Mar 29, 2023
e29f109
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
heitortanoue Apr 12, 2023
7974861
add omnichannel rooms as default
heitortanoue Apr 12, 2023
76e6103
make all checkboxes true by default
heitortanoue Apr 12, 2023
6d257e4
Merge branch 'develop' into fix/admin-rooms-checkboxes
matheusbsilva137 Apr 17, 2023
5989f67
fix room conflicts
heitortanoue May 5, 2023
e1b180c
Merge branch 'develop' into fix/admin-rooms-checkboxes
heitortanoue May 8, 2023
c49945a
Merge branch 'develop' into fix/admin-rooms-checkboxes
matheusbsilva137 May 9, 2023
89cea47
Remove old js file
matheusbsilva137 May 9, 2023
2286c33
Merge branch 'develop' into fix/admin-rooms-checkboxes
matheusbsilva137 May 22, 2023
1b0dcb9
Add changesets
matheusbsilva137 May 22, 2023
f4a67d3
Update changesets
matheusbsilva137 May 22, 2023
8791f5f
Merge branch 'develop' into fix/admin-rooms-checkboxes
matheusbsilva137 Jun 9, 2023
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
12 changes: 2 additions & 10 deletions apps/meteor/app/api/server/lib/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function findAdminRooms({
}: {
uid: string;
filter: string;
types: string[];
types: string[] | undefined;
pagination: { offset: number; count: number; sort: Record<string, 1 | -1> };
}): Promise<{
rooms: IRoom[];
Expand All @@ -27,7 +27,6 @@ export async function findAdminRooms({
const name = filter?.trim();
const discussion = types?.includes('discussions');
const includeTeams = types?.includes('teams');
const showOnlyTeams = types.length === 1 && types.includes('teams');
const typesToRemove = ['discussions', 'teams'];
const showTypes = Array.isArray(types) ? types.filter((type) => !typesToRemove.includes(type)) : [];
const options = {
Expand All @@ -36,14 +35,7 @@ export async function findAdminRooms({
limit: count,
};

let result;
if (name && showTypes.length) {
result = Rooms.findByNameOrFnameContainingAndTypes(name, showTypes, discussion, includeTeams, showOnlyTeams, options);
} else if (showTypes.length) {
result = Rooms.findByTypes(showTypes, discussion, includeTeams, showOnlyTeams, options);
} else {
result = Rooms.findByNameOrFnameContaining(name, discussion, includeTeams, showOnlyTeams, options);
}
const result = Rooms.findByNameOrFnameContainingAndTypes(name, showTypes, discussion, includeTeams, options);

const { cursor, totalCount } = result;

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ API.v1.addRoute(
await findAdminRooms({
uid: this.userId,
filter: filter || '',
types: types || [],
types: types && !Array.isArray(types) ? [types] : undefined,
heitortanoue marked this conversation as resolved.
Show resolved Hide resolved
pagination: {
offset,
count,
Expand Down
112 changes: 37 additions & 75 deletions apps/meteor/server/models/raw/Rooms.js
matheusbsilva137 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -127,85 +127,47 @@ export class RoomsRaw extends BaseRaw {
return statistic;
}

findByNameOrFnameContainingAndTypes(name, types, discussion = false, teams = false, showOnlyTeams = false, options = {}) {
findByNameOrFnameContainingAndTypes(name, types, discussion = false, teams = false, options = {}) {
const nameRegex = new RegExp(escapeRegExp(name).trim(), 'i');

const onlyTeamsQuery = showOnlyTeams ? { teamMain: { $exists: true } } : {};

const teamCondition = teams
? {}
: {
teamMain: {
$exists: false,
},
};

const query = {
t: {
$in: types,
},
prid: { $exists: discussion },
$or: [
{ name: nameRegex, federated: { $ne: true } },
{ fname: nameRegex },
{
t: 'd',
usernames: nameRegex,
},
],
...teamCondition,
...onlyTeamsQuery,
};
return this.findPaginated(query, options);
}

findByTypes(types, discussion = false, teams = false, onlyTeams = false, options = {}) {
const teamCondition = teams
? {}
: {
teamMain: {
$exists: false,
},
};

const onlyTeamsCondition = onlyTeams ? { teamMain: { $exists: true } } : {};

const query = {
t: {
$in: types,
},
prid: { $exists: discussion },
...teamCondition,
...onlyTeamsCondition,
};
return this.findPaginated(query, options);
}

findByNameOrFnameContaining(name, discussion = false, teams = false, onlyTeams = false, options = {}) {
const nameRegex = new RegExp(escapeRegExp(name).trim(), 'i');

const teamCondition = teams
? {}
: {
teamMain: {
$exists: false,
},
};

const onlyTeamsCondition = onlyTeams ? { $and: [{ teamMain: { $exists: true } }, { teamMain: true }] } : {};

const query = {
prid: { $exists: discussion },
$or: [
{ name: nameRegex, federated: { $ne: true } },
{ fname: nameRegex },
{
t: 'd',
usernames: nameRegex,
},
$and: [
name
? {
$or: [
{ name: nameRegex, federated: { $ne: true } },
{ fname: nameRegex },
{
t: 'd',
usernames: nameRegex,
},
],
}
: {},
types && types.length
? {
$or: [
{
t: {
$in: types,
},
},
...(discussion ? [{ prid: { $exists: true } }] : []),
...(teams
? [
{
teamMain: {
$exists: true,
},
},
]
: []),
],
}
: {},
],
...teamCondition,
...onlyTeamsCondition,
...(!discussion ? { prid: { $exists: false } } : {}),
...(!teams ? { teamMain: { $exists: false } } : {}),
};

return this.findPaginated(query, options);
Expand Down
82 changes: 81 additions & 1 deletion apps/meteor/tests/end-to-end/api/09-rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1303,10 +1303,23 @@ describe('[Rooms]', function () {
const suffix = `test-${Date.now()}`;
const fnameRoom = `Ελληνικά-${suffix}`;
const nameRoom = `Ellinika-${suffix}`;
const discussionRoomName = `${nameRoom}-discussion`;

let testGroup;

before((done) => {
updateSetting('UI_Allow_room_names_with_special_chars', true).then(() => {
createRoom({ type: 'p', name: fnameRoom }).end(done);
createRoom({ type: 'p', name: fnameRoom }).end((err, res) => {
testGroup = res.body.group;
request
.post(api('rooms.createDiscussion'))
.set(credentials)
.send({
prid: testGroup._id,
t_name: discussionRoomName,
})
.end(done);
});
});
});

Expand Down Expand Up @@ -1397,6 +1410,73 @@ describe('[Rooms]', function () {
.end(done);
});
});
it('should filter by only rooms types', (done) => {
request
.get(api('rooms.adminRooms'))
.set(credentials)
.query({
types: ['p'],
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('rooms').and.to.be.an('array');
expect(res.body.rooms).to.have.lengthOf.at.least(1);
expect(res.body.rooms[0].t).to.be.equal('p');
expect(res.body.rooms.find((room) => room.name === nameRoom)).to.exist;
expect(res.body.rooms.find((room) => room.name === discussionRoomName)).to.not.exist;
})
.end(done);
});
it('should filter by only name', (done) => {
request
.get(api('rooms.adminRooms'))
.set(credentials)
.query({
filter: nameRoom,
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('rooms').and.to.be.an('array');
expect(res.body.rooms).to.have.lengthOf(1);
expect(res.body.rooms[0].name).to.be.equal(nameRoom);
})
.end(done);
});
it('should filter by type and name at the same query', (done) => {
request
.get(api('rooms.adminRooms'))
.set(credentials)
.query({
filter: nameRoom,
types: ['p'],
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('rooms').and.to.be.an('array');
expect(res.body.rooms).to.have.lengthOf(1);
expect(res.body.rooms[0].name).to.be.equal(nameRoom);
})
.end(done);
});
it('should return an empty array when filter by wrong type and correct room name', (done) => {
request
.get(api('rooms.adminRooms'))
.set(credentials)
.query({
filter: nameRoom,
types: ['c'],
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('rooms').and.to.be.an('array');
expect(res.body.rooms).to.have.lengthOf(0);
})
.end(done);
});
});

describe('update group dms name', () => {
Expand Down
13 changes: 1 addition & 12 deletions packages/model-typings/src/models/IRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@ export interface IRoomsModel extends IBaseModel<IRoom> {

getMostRecentAverageChatDurationTime(numberMostRecentChats: any, department: any): Promise<any>;

findByNameOrFnameContainingAndTypes(
name: any,
types: any,
discussion?: boolean,
teams?: boolean,
showOnlyTeams?: boolean,
options?: any,
): any;

findByTypes(types: any, discussion?: boolean, teams?: boolean, onlyTeams?: boolean, options?: any): any;

findByNameOrFnameContaining(name: any, discussion?: boolean, teams?: boolean, onlyTeams?: boolean, options?: any): any;
findByNameOrFnameContainingAndTypes(name: any, types: any, discussion?: boolean, teams?: boolean, options?: any): any;
heitortanoue marked this conversation as resolved.
Show resolved Hide resolved

findByTeamId(teamId: any, options?: any): any;

Expand Down