mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-28 14:58:55 +00:00
fix: hidden custom fields being validated on some cases (#29556)
Co-authored-by: Kevin Aleman <kaleman960@gmail.com>
This commit is contained in:
parent
0fb7d90708
commit
0f0b8e17bf
6
.changeset/pretty-clocks-add.md
Normal file
6
.changeset/pretty-clocks-add.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@rocket.chat/meteor": patch
|
||||
"@rocket.chat/model-typings": patch
|
||||
---
|
||||
|
||||
fix: hidden custom fields being required in some cases
|
||||
@ -72,9 +72,13 @@ export const Contacts = {
|
||||
}
|
||||
}
|
||||
|
||||
const allowedCF = LivechatCustomField.findByScope<Pick<ILivechatCustomField, '_id' | 'label' | 'regexp' | 'required'>>('visitor', {
|
||||
projection: { _id: 1, label: 1, regexp: 1, required: 1 },
|
||||
});
|
||||
const allowedCF = LivechatCustomField.findByScope<Pick<ILivechatCustomField, '_id' | 'label' | 'regexp' | 'required' | 'visibility'>>(
|
||||
'visitor',
|
||||
{
|
||||
projection: { _id: 1, label: 1, regexp: 1, required: 1 },
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
const livechatData: Record<string, string> = {};
|
||||
|
||||
|
||||
@ -13,8 +13,12 @@ export class LivechatCustomFieldRaw extends BaseRaw<ILivechatCustomField> implem
|
||||
return [{ key: { scope: 1 } }];
|
||||
}
|
||||
|
||||
findByScope(scope: ILivechatCustomField['scope'], options?: FindOptions<ILivechatCustomField>): FindCursor<ILivechatCustomField> {
|
||||
return this.find({ scope }, options || {});
|
||||
findByScope(
|
||||
scope: ILivechatCustomField['scope'],
|
||||
options?: FindOptions<ILivechatCustomField>,
|
||||
includeHidden = true,
|
||||
): FindCursor<ILivechatCustomField> {
|
||||
return this.find({ scope, ...(includeHidden === true ? {} : { visibility: { $ne: 'hidden' } }) }, options);
|
||||
}
|
||||
|
||||
findMatchingCustomFields(
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
import { createToken } from '../../client/lib/utils/createToken';
|
||||
import { IS_EE } from './config/constants';
|
||||
import { Users } from './fixtures/userStates';
|
||||
import { OmnichannelContacts } from './page-objects/omnichannel-contacts-list';
|
||||
import { OmnichannelSection } from './page-objects/omnichannel-section';
|
||||
@ -18,6 +19,16 @@ const createContact = (generateToken = false) => ({
|
||||
const NEW_CONTACT = createContact();
|
||||
const EDIT_CONTACT = createContact();
|
||||
const EXISTING_CONTACT = createContact(true);
|
||||
const NEW_CUSTOM_FIELD = {
|
||||
searchable: true,
|
||||
field: 'hiddenCustomField',
|
||||
label: 'hiddenCustomField',
|
||||
defaultValue: 'test_contact_center_hidden_customField',
|
||||
scope: 'visitor',
|
||||
visibility: 'hidden',
|
||||
required: true,
|
||||
regexp: '',
|
||||
}
|
||||
|
||||
const URL = {
|
||||
contactCenter: '/omnichannel-directory/contacts',
|
||||
@ -47,12 +58,19 @@ test.describe('Omnichannel Contact Center', () => {
|
||||
// Add a contact
|
||||
const { id: _, ...data } = EXISTING_CONTACT;
|
||||
await api.post('/omnichannel/contact', data);
|
||||
|
||||
if (IS_EE) {
|
||||
await api.post('/livechat/custom.field', NEW_CUSTOM_FIELD);
|
||||
}
|
||||
});
|
||||
|
||||
test.afterAll(async ({ api }) => {
|
||||
// Remove added contacts
|
||||
await api.delete('/livechat/visitor', { token: EXISTING_CONTACT.token });
|
||||
await api.delete('/livechat/visitor', { token: NEW_CONTACT.token });
|
||||
if (IS_EE) {
|
||||
await api.post('method.call/livechat:removeCustomField', { message: NEW_CUSTOM_FIELD.field });
|
||||
}
|
||||
});
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
|
||||
@ -5,8 +5,16 @@ import type { IBaseModel } from './IBaseModel';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface ILivechatCustomFieldModel extends IBaseModel<ILivechatCustomField> {
|
||||
findByScope<T extends Document = ILivechatCustomField>(scope: ILivechatCustomField['scope'], options?: FindOptions<T>): FindCursor<T>;
|
||||
findByScope(scope: ILivechatCustomField['scope'], options?: FindOptions<ILivechatCustomField>): FindCursor<ILivechatCustomField>;
|
||||
findByScope<T extends Document = ILivechatCustomField>(
|
||||
scope: ILivechatCustomField['scope'],
|
||||
options?: FindOptions<T>,
|
||||
includeHidden?: boolean,
|
||||
): FindCursor<T>;
|
||||
findByScope(
|
||||
scope: ILivechatCustomField['scope'],
|
||||
options?: FindOptions<ILivechatCustomField>,
|
||||
includeHidden?: boolean,
|
||||
): FindCursor<ILivechatCustomField>;
|
||||
findMatchingCustomFields(
|
||||
scope: ILivechatCustomField['scope'],
|
||||
searchable: boolean,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user