Skip to content

Commit

Permalink
chore!: remove query field on online channels listing (#33646)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogarim authored Oct 18, 2024
1 parent d879c8b commit f835e35
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions apps/meteor/app/api/server/helpers/parseJsonQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{
'/api/v1/custom-user-status.list',
'/api/v1/custom-sounds.list',
'/api/v1/channels.list',
'/api/v1/channels.online',
].includes(route);

const isUnsafeQueryParamsAllowed = process.env.ALLOW_UNSAFE_QUERY_AND_FIELDS_API_PARAMS?.toUpperCase() === 'TRUE';
Expand Down
15 changes: 11 additions & 4 deletions apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
isChannelsDeleteProps,
isChannelsListProps,
isChannelsFilesListProps,
isChannelsOnlineProps,
} from '@rocket.chat/rest-typings';
import { Meteor } from 'meteor/meteor';

Expand Down Expand Up @@ -1083,17 +1084,23 @@ API.v1.addRoute(

API.v1.addRoute(
'channels.online',
{ authRequired: true },
{ authRequired: true, validateParams: isChannelsOnlineProps },
{
async get() {
const { query } = await this.parseJsonQuery();
if (!query || Object.keys(query).length === 0) {
const { _id } = this.queryParams;

if ((!query || Object.keys(query).length === 0) && !_id) {
return API.v1.failure('Invalid query');
}

const ourQuery = Object.assign({}, query, { t: 'c' });
const filter = {
...query,
...(_id ? { _id } : {}),
t: 'c',
};

const room = await Rooms.findOne(ourQuery as Record<string, any>);
const room = await Rooms.findOne(filter as Record<string, any>);
if (!room) {
return API.v1.failure('Channel does not exists');
}
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/tests/end-to-end/api/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ describe('[Channels]', () => {
return request
.get(api('channels.online'))
.set(testUserCredentials)
.query(`query={"_id": "${room._id}"}`)
.query({ _id: room._id })
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
Expand All @@ -1025,7 +1025,7 @@ describe('[Channels]', () => {
return request
.get(api('channels.online'))
.set(outsiderCredentials)
.query(`query={"_id": "${room._id}"}`)
.query({ _id: room._id })
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/rest-typings/src/v1/channels/ChannelsOnlineProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ const ajv = new Ajv({
coerceTypes: true,
});

export type ChannelsOnlineProps = { query?: Record<string, any> };
export type ChannelsOnlineProps = { _id?: string; query?: Record<string, any> };
const channelsOnlyPropsSchema = {
type: 'object',
properties: {
_id: {
type: 'string',
nullable: true,
},
query: {
type: 'string',
nullable: true,
Expand Down
1 change: 1 addition & 0 deletions packages/rest-typings/src/v1/channels/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { ChannelsUnarchiveProps } from './ChannelsUnarchiveProps';

export * from './ChannelsFilesListProps';
export * from './ChannelsListProps';
export * from './ChannelsOnlineProps';

export type ChannelsEndpoints = {
'/v1/channels.files': {
Expand Down

0 comments on commit f835e35

Please sign in to comment.