Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/old-cobras-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes an issue where private channels that a user belongs to were not shown in Directory search results.
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ API.v1.addRoute(
const sortBy = sort ? Object.keys(sort)[0] : undefined;
const sortDirection = sort && Object.values(sort)[0] === 1 ? 'asc' : 'desc';

const user = await Users.findOneById(this.userId, { projection: { __rooms: 1 } });
const result = await browseChannelsMethod(
{
...filter,
Expand All @@ -372,7 +373,7 @@ API.v1.addRoute(
offset: Math.max(0, offset),
limit: Math.max(0, count),
},
this.user,
user,
);

if (!result) {
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/server/methods/browseChannels.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Team } from '@rocket.chat/core-services';
import type { IRoom, IUser } from '@rocket.chat/core-typings';
import type { IUser, AtLeast } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Rooms, Users, Subscriptions } from '@rocket.chat/models';
import { escapeRegExp } from '@rocket.chat/string-helpers';
Expand Down Expand Up @@ -45,7 +45,7 @@ const sortUsers = (field: string, direction: 'asc' | 'desc'): Record<string, Sor
};

const getChannelsAndGroups = async (
user: IUser & { __rooms?: IRoom['_id'][] },
user: AtLeast<IUser, '_id' | '__rooms'>,
canViewAnon: boolean,
searchTerm: string,
sort: Record<string, number>,
Expand Down Expand Up @@ -119,7 +119,7 @@ const getChannelsCountForTeam = mem((teamId) => Rooms.countByTeamId(teamId), {
});

const getTeams = async (
user: IUser,
user: AtLeast<IUser, '_id' | '__rooms'>,
searchTerm: string,
sort: Record<string, number>,
pagination: {
Expand Down Expand Up @@ -247,7 +247,7 @@ const findUsers = async ({
};

const getUsers = async (
user: IUser | undefined,
user: AtLeast<IUser, '_id' | '__rooms'> | undefined,
text: string,
workspace: string,
sort: Record<string, SortDirection>,
Expand Down Expand Up @@ -299,7 +299,7 @@ export const browseChannelsMethod = async (
offset = 0,
limit = 10,
}: BrowseChannelsParams,
user: IUser | undefined | null,
user: AtLeast<IUser, '_id' | '__rooms'> | undefined | null,
) => {
const searchTerm = trim(escapeRegExp(text));

Expand Down
34 changes: 32 additions & 2 deletions apps/meteor/tests/end-to-end/api/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ describe('miscellaneous', () => {
describe('/directory', () => {
let user: TestUser<IUser>;
let testChannel: IRoom;
let testGroup: IRoom;
let normalUserCredentials: Credentials;
const teamName = `new-team-name-${Date.now()}` as const;
let teamCreated: ITeam;
Expand All @@ -223,15 +224,19 @@ describe('miscellaneous', () => {
await updatePermission('create-team', ['admin', 'user']);
user = await createUser();
normalUserCredentials = await doLogin(user.username, password);
testChannel = (await createRoom({ name: `channel.test.${Date.now()}`, type: 'c' })).body.channel;
teamCreated = await createTeam(normalUserCredentials, teamName, TEAM_TYPE.PUBLIC);
[testChannel, testGroup, teamCreated] = await Promise.all([
createRoom({ name: `channel.test.${Date.now()}`, type: 'c' }).then((res) => res.body.channel),
createRoom({ name: `group.test.${Date.now()}`, type: 'p' }).then((res) => res.body.group),
createTeam(normalUserCredentials, teamName, TEAM_TYPE.PUBLIC),
]);
});

after(async () => {
await Promise.all([
deleteTeam(normalUserCredentials, teamName),
deleteUser(user),
deleteRoom({ type: 'c', roomId: testChannel._id }),
deleteRoom({ type: 'p', roomId: testGroup._id }),
updatePermission('create-team', ['admin', 'user']),
]);
});
Expand Down Expand Up @@ -308,6 +313,31 @@ describe('miscellaneous', () => {
})
.end(done);
});

it('should return private group when search by channel and execute successfully', async () => {
await request
.get(api('directory'))
.set(credentials)
.query({
text: testGroup.name,
type: 'channels',
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('offset');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('result').and.to.be.an('array');
expect(res.body.result[0]).to.have.property('_id', testGroup._id);
expect(res.body.result[0]).to.have.property('t', 'p');
expect(res.body.result[0]).to.have.property('name');
expect(res.body.result[0]).to.have.property('usersCount').and.to.be.an('number');
expect(res.body.result[0]).to.have.property('ts');
});
});

it('should return an array(result) when search by channel with sort params correctly and execute successfully', (done) => {
void request
.get(api('directory'))
Expand Down
Loading