fix: hidden custom fields being validated on some cases (#29556)

Co-authored-by: Kevin Aleman <kaleman960@gmail.com>
pull/28240/head^2
Martin Schoeler 3 years ago committed by GitHub
parent 0fb7d90708
commit 0f0b8e17bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .changeset/pretty-clocks-add.md
  2. 10
      apps/meteor/app/livechat/server/lib/Contacts.ts
  3. 8
      apps/meteor/server/models/raw/LivechatCustomField.ts
  4. 18
      apps/meteor/tests/e2e/omnichannel-contact-center.spec.ts
  5. 12
      packages/model-typings/src/models/ILivechatCustomFieldModel.ts

@ -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…
Cancel
Save