Skip to content

Commit d065200

Browse files
fix: Encrypted toggle ignored when creating a discussion
The "Encrypted" toggle in the Create Discussion dialog was destructured in handleCreate but never included in the rooms.createDiscussion payload. As a result, discussions created from an unencrypted parent room were always created unencrypted, regardless of the toggle state. Pass the selected `encrypted` value to the endpoint (which, along with the REST schema, already supports it) and add a regression test. Closes #39443
1 parent 7b54fb7 commit d065200

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixed the **Encrypted** toggle being ignored when creating a discussion from an unencrypted parent room. The `encrypted` flag selected in the Create Discussion dialog was not sent to the API, so the discussion was created unencrypted even though the user explicitly enabled encryption.

‎apps/meteor/client/components/CreateDiscussion/CreateDiscussion.spec.tsx‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,54 @@ describe('CreateDiscussion', () => {
6363
expect(results).toHaveNoViolations();
6464
});
6565

66+
describe('Encrypted flag submission', () => {
67+
it('should send encrypted: true to the API when the encrypted toggle is enabled for an unencrypted parent room', async () => {
68+
const createDiscussionEndpoint = jest.fn().mockReturnValue({
69+
success: true,
70+
discussion: {
71+
...createFakeRoom({ _id: 'discussion-id', t: 'p' as const, prid: room2._id }),
72+
rid: 'discussion-id',
73+
} as any,
74+
});
75+
76+
const appRootWithSpy = mockAppRoot()
77+
.withEndpoint('POST', '/v1/rooms.createDiscussion', createDiscussionEndpoint)
78+
.withEndpoint('GET', '/v1/rooms.autocomplete.channelAndPrivate', () => ({ items: [room1, room2] }) as any)
79+
.withTranslations('en', 'core', {
80+
Encrypted: 'Encrypted',
81+
Name: 'Name',
82+
Create: 'Create',
83+
Discussion_target_channel: 'Parent channel or team',
84+
})
85+
.build();
86+
87+
render(<CreateDiscussion onClose={jest.fn()} />, { wrapper: appRootWithSpy });
88+
89+
const parentRoomSelect = screen.getByRole('textbox', { name: 'Parent channel or team' });
90+
await userEvent.click(parentRoomSelect);
91+
await waitFor(() => {
92+
expect(screen.getByText('Unencrypted Room 2')).toBeInTheDocument();
93+
});
94+
await userEvent.click(screen.getByText('Unencrypted Room 2'));
95+
96+
await userEvent.type(screen.getByLabelText('Name'), 'My secret discussion');
97+
98+
await userEvent.click(screen.getByRole('checkbox', { name: 'Encrypted' }));
99+
100+
await userEvent.click(screen.getByRole('button', { name: 'Create' }));
101+
102+
await waitFor(() => {
103+
expect(createDiscussionEndpoint).toHaveBeenCalledWith(
104+
expect.objectContaining({
105+
prid: room2._id,
106+
t_name: 'My secret discussion',
107+
encrypted: true,
108+
}),
109+
);
110+
});
111+
});
112+
});
113+
66114
describe('Encrypted parent room behavior', () => {
67115
it('should disable encrypted toggle and first message field when parent room is encrypted', () => {
68116
render(<CreateDiscussion onClose={jest.fn()} encryptedParentRoom={true} />, { wrapper: appRoot });

‎apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const CreateDiscussion = ({
9696
prid: defaultParentRoom || parentRoom,
9797
t_name: name,
9898
users: usernames,
99+
encrypted,
99100
reply: encrypted ? undefined : firstMessage,
100101
topic,
101102
...(parentMessageId && { pmid: parentMessageId }),

0 commit comments

Comments
 (0)