Skip to content

Commit

Permalink
Merge branch 'develop' into bump-dependencies-lodash-matrix-highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
julio-rocketchat authored Jan 24, 2025
2 parents 23d839a + 483cb99 commit 43a359d
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-insects-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes a missconception about `/v1/livechat/tags/:tagId` returning 404 if tag is not found
6 changes: 6 additions & 0 deletions .changeset/violet-bikes-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/i18n": patch
---

Fixes issue where a invalid `Accounts_CustomFieldsToShowInUserInfo` value would break the ui
23 changes: 23 additions & 0 deletions apps/meteor/client/hooks/useUserCustomFields.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook, waitFor } from '@testing-library/react';

import { useUserCustomFields } from './useUserCustomFields';

it('should not break with invalid Accounts_CustomFieldsToShowInUserInfo setting', async () => {
const { result } = renderHook(
() =>
useUserCustomFields({
prop: 'value',
}),
{
legacyRoot: true,
wrapper: mockAppRoot()
.withSetting('Accounts_CustomFieldsToShowInUserInfo', '{"Invalid": "Object", "InvalidProperty": "Invalid" }')
.build(),
},
);

await waitFor(() => !!result.current);

expect(result.current).toEqual(undefined);
});
5 changes: 5 additions & 0 deletions apps/meteor/client/hooks/useUserCustomFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export const useUserCustomFields = (customFields: CustomField): CustomFieldDispl
return undefined;
}

if (!Array.isArray(customFieldsToShowObj)) {
console.warn('Invalid customFieldsToShowInUserInfo value');
return undefined;
}

const customFieldsToShow = customFieldsToShowObj.map((value) => {
if (!value) {
return undefined;
Expand Down
16 changes: 10 additions & 6 deletions apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ API.v1.addRoute(
async get() {
const { tagId } = this.urlParams;

return API.v1.success(
await findTagById({
userId: this.userId,
tagId,
}),
);
const tag = await findTagById({
userId: this.userId,
tagId,
});

if (!tag) {
return API.v1.notFound('Tag not found');
}

return API.v1.success(tag);
},
},
);
1 change: 1 addition & 0 deletions apps/meteor/server/settings/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export const createAccountSettings = () =>
await this.add('Accounts_CustomFieldsToShowInUserInfo', '', {
type: 'string',
public: true,
i18nDescription: 'Accounts_CustomFieldsToShowInUserInfo_Description',
});
await this.add('Accounts_LoginExpiration', 90, {
type: 'int',
Expand Down
28 changes: 21 additions & 7 deletions apps/meteor/tests/e2e/feature-preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,14 @@ test.describe.serial('feature preview', () => {

await poHomeChannel.tabs.btnChannels.click();
await poHomeChannel.tabs.channels.btnAddExisting.click();
await poHomeChannel.tabs.channels.inputChannels.fill(targetChannel);
await page.getByRole('listbox').getByRole('option', { name: targetChannel }).click();
// flaky: workarround for when AutoComplete does not close the list box before trying to click `Add`
await expect(async () => {
await poHomeChannel.tabs.channels.inputChannels.fill(targetChannel);
const option = poHomeChannel.tabs.channels.getListboxOption(targetChannel);
await option.click();
await expect(option).not.toBeVisible();
}).toPass();

await poHomeChannel.tabs.channels.btnAdd.click();
await poHomeChannel.content.waitForChannel();

Expand All @@ -288,8 +294,13 @@ test.describe.serial('feature preview', () => {

await poHomeChannel.tabs.btnChannels.click();
await poHomeChannel.tabs.channels.btnAddExisting.click();
await poHomeChannel.tabs.channels.inputChannels.fill(targetChannel);
await page.getByRole('listbox').getByRole('option', { name: targetChannel }).click();
// flaky: workarround for when AutoComplete does not close the list box before trying to click `Add`
await expect(async () => {
await poHomeChannel.tabs.channels.inputChannels.fill(targetChannel);
const option = poHomeChannel.tabs.channels.getListboxOption(targetChannel);
await option.click();
await expect(option).not.toBeVisible();
}).toPass();
await poHomeChannel.tabs.channels.btnAdd.click();

const sidepanelTeamItem = poHomeChannel.sidepanel.getItemByName(sidepanelTeam);
Expand All @@ -298,9 +309,12 @@ test.describe.serial('feature preview', () => {
await targetChannelItem.click();
expect(page.url()).toContain(`/channel/${targetChannel}`);
await poHomeChannel.content.sendMessage('hello channel');
await sidepanelTeamItem.focus();
await sidepanelTeamItem.click();
expect(page.url()).toContain(`/group/${sidepanelTeam}`);

await expect(async () => {
await sidepanelTeamItem.focus();
await sidepanelTeamItem.click();
expect(page.url()).toContain(`/group/${sidepanelTeam}`);
}).toPass();
await poHomeChannel.content.sendMessage('hello team');

await user1Page.goto(`/channel/${targetChannel}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class HomeFlextabChannels {
}

get inputChannels(): Locator {
return this.page.locator('#modal-root input').first();
return this.page.locator('#modal-root').getByRole('dialog').getByRole('textbox');
}

get btnAdd(): Locator {
Expand All @@ -31,6 +31,10 @@ export class HomeFlextabChannels {
return this.channelsTab.getByRole('list');
}

getListboxOption(name: string): Locator {
return this.page.getByRole('listbox').getByRole('option', { name });
}

channelOption(name: string) {
return this.channelsTab.locator('li', { hasText: name });
}
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/tests/end-to-end/api/livechat/13-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ import { IS_EE } from '../../../e2e/config/constants';
it('should return null when the tag does not exist', async () => {
await updatePermission('manage-livechat-tags', ['admin']);
await updatePermission('view-l-room', ['livechat-agent']);
const response = await request.get(api('livechat/tags/123')).set(credentials).expect('Content-Type', 'application/json').expect(200);
expect(response.body.body).to.be.null;
await request.get(api('livechat/tags/123')).set(credentials).expect('Content-Type', 'application/json').expect(404);
});
it('should return a tag', async () => {
const tag = await saveTags();
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"Accounts_BlockedUsernameList_Description": "Comma-separated list of blocked usernames (case-insensitive)",
"Accounts_CustomFields_Description": "Should be a valid JSON where keys are the field names containing a dictionary of field settings. Example: \n`{\"role\":{ \"type\": \"select\", \"defaultValue\": \"student\", \"options\": [\"teacher\", \"student\"], \"required\": true, \"modifyRecordField\": { \"array\": true, \"field\": \"roles\" } }, \"twitter\": { \"type\": \"text\", \"required\": true, \"minLength\": 2, \"maxLength\": 10 }}`",
"Accounts_CustomFieldsToShowInUserInfo": "Custom Fields to Show in User Info",
"Accounts_CustomFieldsToShowInUserInfo_Description": "Value must be an array of objects where the key is the label and the value the field name. Example: `[{\"Role Label\": \"role\"}, {\"Twitter Label\": \"twitter\"}]` more info at [Custom Fields](https://docs.rocket.chat/docs/custom-fields)",
"Accounts_Default_User_Preferences": "Default User Preferences",
"Accounts_Default_User_Preferences_audioNotifications": "Audio Notifications Default Alert",
"Accounts_Default_User_Preferences_alsoSendThreadToChannel_Description": "Allow users to select the Also send to channel behavior",
Expand Down

0 comments on commit 43a359d

Please sign in to comment.