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
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
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
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
Loading