Skip to content

Commit

Permalink
fix browseChannels
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Jul 15, 2022
1 parent 81555fe commit a4d81d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
20 changes: 4 additions & 16 deletions apps/meteor/app/api/server/v1/im.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@rocket.chat/rest-typings';
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { Subscriptions, Uploads, Messages, Rooms, Settings, Users } from '@rocket.chat/models';
import { Subscriptions, Uploads, Messages, Rooms, Users } from '@rocket.chat/models';

import { canAccessRoomIdAsync } from '../../../authorization/server/functions/canAccessRoom';
import { hasPermission } from '../../../authorization/server';
Expand All @@ -21,6 +21,7 @@ import { API } from '../api';
import { getRoomByNameOrIdWithOptionToJoin } from '../../../lib/server/functions/getRoomByNameOrIdWithOptionToJoin';
import { createDirectMessage } from '../../../../server/methods/createDirectMessage';
import { addUserToFileObj } from '../helpers/addUserToFileObj';
import { settings } from '../../../settings/server';

interface IImFilesObject extends IUpload {
userId: string;
Expand Down Expand Up @@ -310,14 +311,7 @@ API.v1.addRoute(
limit: count,
};

const searchFieldsSetting = await Settings.findOne<ISetting>(
{ _id: 'Accounts_SearchFields' },
{
projection: { value: 1 },
},
);

const searchFields = (searchFieldsSetting?.value as string | undefined)?.trim().split(',');
const searchFields = settings.get<string>('Accounts_SearchFields').trim().split(',');

const { cursor, totalCount } = Users.findPaginatedByActiveUsersExcept(filter, [], options, searchFields, [extraQuery]);

Expand Down Expand Up @@ -378,13 +372,7 @@ API.v1.addRoute(
{ authRequired: true },
{
async get() {
const settings = await Settings.findOne<ISetting>(
{ _id: 'API_Enable_Direct_Message_History_EndPoint' },
{
projection: { _id: 1, value: 1 },
},
);
if (settings?.value !== true) {
if (settings.get('API_Enable_Direct_Message_History_EndPoint') !== true) {
throw new Meteor.Error('error-endpoint-disabled', 'This endpoint is disabled', {
route: '/api/v1/im.messages.others',
});
Expand Down
15 changes: 5 additions & 10 deletions apps/meteor/server/methods/browseChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ async function getTeams(user, searchTerm, sort, pagination) {
}

async function findUsers({ text, sort, pagination, workspace, viewFullOtherUserInfo }) {
const forcedSearchFields = workspace === 'all' && ['username', 'name', 'emails.address'];
const searchFields =
workspace === 'all' ? ['username', 'name', 'emails.address'] : settings.get('Accounts_SearchFields').trim().split(',');

const options = {
...pagination,
Expand All @@ -178,7 +179,7 @@ async function findUsers({ text, sort, pagination, workspace, viewFullOtherUserI
};

if (workspace === 'all') {
const { cursor, totalCount } = Users.findPaginatedByActiveUsersExcept(text, [], options, forcedSearchFields);
const { cursor, totalCount } = Users.findPaginatedByActiveUsersExcept(text, [], options, searchFields);
const [results, total] = await Promise.all([cursor.toArray(), totalCount]);
return {
total,
Expand All @@ -187,21 +188,15 @@ async function findUsers({ text, sort, pagination, workspace, viewFullOtherUserI
}

if (workspace === 'external') {
const { cursor, totalCount } = Users.findPaginatedByActiveLocalUsersExcept(
text,
[],
options,
forcedSearchFields,
getFederationDomain(),
);
const { cursor, totalCount } = Users.findPaginatedByActiveExternalUsersExcept(text, [], options, searchFields, getFederationDomain());
const [results, total] = await Promise.all([cursor.toArray(), totalCount]);
return {
total,
results,
};
}

const { cursor, totalCount } = Users.findPaginatedByActiveLocalUsersExcept(text, [], options, forcedSearchFields, getFederationDomain());
const { cursor, totalCount } = Users.findPaginatedByActiveLocalUsersExcept(text, [], options, searchFields, getFederationDomain());
const [results, total] = await Promise.all([cursor.toArray(), totalCount]);
return {
total,
Expand Down

0 comments on commit a4d81d4

Please sign in to comment.