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/new-students-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes an issue when forwarding messages to a password-protected room.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Room } from '@rocket.chat/core-services';
import type { IRoom, IUser, RoomType } from '@rocket.chat/core-typings';
import { Rooms, Users } from '@rocket.chat/models';
import { Rooms, Subscriptions, Users } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { isObject } from '../../../../lib/utils/isObject';
Expand Down Expand Up @@ -88,7 +88,10 @@ export const getRoomByNameOrIdWithOptionToJoin = async ({
// If the room type is channel and joinChannel has been passed, try to join them
// if they can't join the room, this will error out!
if (room.t === 'c' && joinChannel) {
await Room.join({ room, user });
const sub = await Subscriptions.findOneByRoomIdAndUserId(room._id, user._id, { projection: { _id: 1 } });
if (!sub) {
await Room.join({ room, user });
}
}

return room;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/sidebar/footer/SidebarFooterDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@rocket.chat/css-in-js';
import { Box, SidebarDivider, Palette, SidebarFooter as Footer } from '@rocket.chat/fuselage';
import { useThemeMode } from '@rocket.chat/ui-client';
import { useSetting } from '@rocket.chat/ui-contexts';
import { useThemeMode } from '@rocket.chat/ui-theming';
import DOMPurify from 'dompurify';
import type { ReactElement } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/root/AppErrorPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, PaletteStyleTag, States, StatesAction, StatesActions, StatesIcon, StatesSubtitle, StatesTitle } from '@rocket.chat/fuselage';
import { useThemeMode } from '@rocket.chat/ui-theming';
import { useThemeMode } from '@rocket.chat/ui-client';
import type { ErrorInfo, ReactElement } from 'react';

type AppErrorPageProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jest.mock('../../navigation/providers/RoomsNavigationProvider', () => ({
}));

jest.mock('@rocket.chat/ui-client', () => ({
...jest.requireActual('@rocket.chat/ui-client'),
FeaturePreview: ({ children }: { children: ReactNode }) => <>{children}</>,
FeaturePreviewOn: ({ children }: { children: ReactNode }) => <>{children}</>,
FeaturePreviewOff: ({ children }: { children: ReactNode }) => <>{children}</>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PaletteStyleTag } from '@rocket.chat/fuselage';
import { useThemeMode } from '@rocket.chat/ui-theming';
import { useThemeMode } from '@rocket.chat/ui-client';

import { codeBlock } from '../lib/codeBlockStyles';

Expand Down
1 change: 0 additions & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
"@rocket.chat/ui-composer": "workspace:^",
"@rocket.chat/ui-contexts": "workspace:^",
"@rocket.chat/ui-kit": "workspace:~",
"@rocket.chat/ui-theming": "workspace:^",
"@rocket.chat/ui-video-conf": "workspace:^",
"@rocket.chat/ui-voip": "workspace:^",
"@rocket.chat/web-ui-registration": "workspace:^",
Expand Down
48 changes: 47 additions & 1 deletion apps/meteor/tests/end-to-end/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,32 @@ const pinMessage = ({ msgId }: { msgId: IMessage['_id'] }) => {
describe('[Chat]', () => {
let testChannel: IRoom;
let message: { _id: IMessage['_id'] };
let protectedChannel: IRoom;

before((done) => getCredentials(done));

before(async () => {
testChannel = (await createRoom({ type: 'c', name: `chat.api-test-${Date.now()}` })).body.channel;
protectedChannel = (await createRoom({ type: 'c', name: `chat.api-protected-test-${Date.now()}` })).body.channel;

await request
.post(api('rooms.saveRoomSettings'))
.set(credentials)
.send({
rid: protectedChannel._id,
joinCode: 'super-secret-password',
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});
});

after(() => deleteRoom({ type: 'c', roomId: testChannel._id }));
after(async () => {
await deleteRoom({ type: 'c', roomId: testChannel._id });
await deleteRoom({ type: 'c', roomId: protectedChannel._id });
});

describe('/chat.postMessage', () => {
it('should throw an error when at least one of required parameters(channel, roomId) is not sent', (done) => {
Expand Down Expand Up @@ -586,6 +604,34 @@ describe('[Chat]', () => {
.end(done);
});

it('should allow forwarding a message into the same password protected room', async () => {
const postResponse = await request
.post(api('chat.postMessage'))
.set(credentials)
.send({
roomId: [protectedChannel._id],
text: 'Message to be forwarded',
})
.expect('Content-Type', 'application/json')
.expect(200);

expect(postResponse.body).to.have.property('success', true);
const originalMessageId = postResponse.body.message._id as IMessage['_id'];

const forwardResponse = await request
.post(api('chat.postMessage'))
.set(credentials)
.send({
roomId: [protectedChannel._id],
text: `[](http://localhost:3000/channel/${protectedChannel.name}?msg=${originalMessageId}`,
})
.expect('Content-Type', 'application/json')
.expect(200);

expect(forwardResponse.body).to.have.property('success', true);
expect(forwardResponse.body).to.have.nested.property('message.rid', protectedChannel._id);
});

it('should return statusCode 200 when postMessage successfully', (done) => {
void request
.post(api('chat.postMessage'))
Expand Down
Loading
Loading