From 7a1ae9177b362cea51a22ac7d3668b010f20d136 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 9 Sep 2019 09:05:13 +0200 Subject: [PATCH] Special characters not allowed on socialName #1635 --- db/dump/fixtures.sql | 8 +++--- .../03_edit_fiscal_data.spec.js | 4 +-- .../12_lock_of_verified_data.spec.js | 6 ++-- front/core/components/scroll-up/scroll-up.js | 1 - front/core/lib/template.js | 28 ++++++++++--------- loopback/locale/en.json | 3 +- loopback/locale/es.json | 3 +- modules/client/back/models/client.js | 10 +++++++ modules/client/front/fiscal-data/index.html | 4 ++- .../client/front/fiscal-data/locale/es.yml | 3 +- 10 files changed, 43 insertions(+), 27 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 770a2c676b..57af97ddbf 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -177,12 +177,12 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`) INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`fax`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`,`mailAddress`,`cplusTerIdNifFk`,`hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`) VALUES (101, 'Bruce Wayne', '84612325V', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (102, 'Petter Parker', '87945234L', 'Spider-Man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (103, 'Clark Kent', '06815934E', 'Super-Man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (104, 'Tony Stark', '06089160W', 'Iron-Man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (102, 'Petter Parker', '87945234L', 'Spider man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), (105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), (106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1), - (107, 'Hank Pym', '09854837G', 'Ant-Man', 'Hawk', 'Anthill', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), + (107, 'Hank Pym', '09854837G', 'Ant man', 'Hawk', 'Anthill', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), (108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), (109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), (110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1), diff --git a/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js b/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js index 4d8d160eb2..b304a03eeb 100644 --- a/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js +++ b/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js @@ -62,7 +62,7 @@ describe('Client Edit fiscalData path', () => { const result = await nightmare .wait(selectors.clientFiscalData.socialNameInput) .clearInput(selectors.clientFiscalData.socialNameInput) - .write(selectors.clientFiscalData.socialNameInput, 'SMASH!') + .write(selectors.clientFiscalData.socialNameInput, 'SMASH') .clearInput(selectors.clientFiscalData.fiscalIdInput) .write(selectors.clientFiscalData.fiscalIdInput, 'INVALID!') .clearInput(selectors.clientFiscalData.addressInput) @@ -175,7 +175,7 @@ describe('Client Edit fiscalData path', () => { .waitToClick(selectors.clientFiscalData.fiscalDataButton) .waitToGetProperty(selectors.clientFiscalData.socialNameInput, 'value'); - expect(result).toEqual('SMASH!'); + expect(result).toEqual('SMASH'); }); it('should confirm the fiscal id have been edited', async() => { diff --git a/e2e/paths/02-client-module/12_lock_of_verified_data.spec.js b/e2e/paths/02-client-module/12_lock_of_verified_data.spec.js index d8378e5771..75b8935d15 100644 --- a/e2e/paths/02-client-module/12_lock_of_verified_data.spec.js +++ b/e2e/paths/02-client-module/12_lock_of_verified_data.spec.js @@ -82,7 +82,7 @@ describe('Client lock verified data path', () => { const result = await nightmare .wait(selectors.clientFiscalData.socialNameInput) .clearInput(selectors.clientFiscalData.socialNameInput) - .write(selectors.clientFiscalData.socialNameInput, 'Ant-Man and the Wasp') + .write(selectors.clientFiscalData.socialNameInput, 'Ant man and the Wasp') .waitToClick(selectors.clientFiscalData.saveButton) .waitForLastSnackbar(); @@ -94,7 +94,7 @@ describe('Client lock verified data path', () => { .reloadSection('client.card.fiscalData') .waitToGetProperty(selectors.clientFiscalData.socialNameInput, 'value'); - expect(result).toEqual('Ant-Man and the Wasp'); + expect(result).toEqual('Ant man and the Wasp'); }); }); @@ -188,7 +188,7 @@ describe('Client lock verified data path', () => { .wait(selectors.clientFiscalData.socialNameInput) .evaluate(selector => { return document.querySelector(selector).disabled; - }, 'vn-textfield[field="$ctrl.client.socialName"] > div'); + }, 'vn-textfield[model="$ctrl.client.socialName"] > div'); expect(result).toBeFalsy(); }); diff --git a/front/core/components/scroll-up/scroll-up.js b/front/core/components/scroll-up/scroll-up.js index aab03847a7..2ada053941 100644 --- a/front/core/components/scroll-up/scroll-up.js +++ b/front/core/components/scroll-up/scroll-up.js @@ -8,7 +8,6 @@ export default class Controller extends Component { this.$window = $window; $window.addEventListener('scroll', () => { - console.log($element[0]); if ($window.scrollY > 0) $element[0].style.display = 'block'; else diff --git a/front/core/lib/template.js b/front/core/lib/template.js index b8aa1b30e3..6be5677dd9 100644 --- a/front/core/lib/template.js +++ b/front/core/lib/template.js @@ -13,30 +13,32 @@ export default class Template { return this.get(template, $attrs, defaults); } normalizeInputAttrs($attrs) { - if ($attrs.field) { - let split = $attrs.field.split('.'); - let len = split.length; + const field = $attrs.field || $attrs.model; + const split = field.split('.'); + const len = split.length; + let i = len - 1; + const fieldName = split[i--]; + const entity = i >= 0 ? split[i--] : 'model'; + const ctrl = i >= 0 ? split[i--] : '$ctrl'; + + if ($attrs.field) { if (len == 0) throw new Error(`Attribute 'field' can not be empty`); if (len > 3) throw new Error(`Attribute 'field' must have this syntax: [ctrl].[entity].[field]`); - let i = len - 1; - let field = split[i--]; - let entity = i >= 0 ? split[i--] : 'model'; - let ctrl = i >= 0 ? split[i--] : '$ctrl'; - if ($attrs.model === undefined) - $attrs.model = `${ctrl}.${entity}.${field}`; + $attrs.model = `${ctrl}.${entity}.${fieldName}`; if ($attrs.rule === undefined && len >= 2) - $attrs.rule = `${entity}.${field}`; + $attrs.rule = `${entity}.${fieldName}`; if ($attrs.label === undefined && len >= 2) - $attrs.label = `${entity}.${field}`; - if ($attrs.name === undefined) - $attrs.name = field; + $attrs.label = `${entity}.${fieldName}`; } + if ($attrs.name === undefined) + $attrs.name = fieldName; + if ($attrs.focus !== undefined) $attrs.focus = 'vn-focus'; } diff --git a/loopback/locale/en.json b/loopback/locale/en.json index cfcb5bbdbb..7aea68f028 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -53,5 +53,6 @@ "Ticket id cannot be blank": "Ticket id cannot be blank", "Weekday cannot be blank": "Weekday cannot be blank", "This ticket can not be modified": "This ticket can not be modified", - "You can't delete a confirmed order": "You can't delete a confirmed order" + "You can't delete a confirmed order": "You can't delete a confirmed order", + "Value has an invalid format": "Value has an invalid format" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4e82aa871a..2a822f5258 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -102,5 +102,6 @@ "Ticket id cannot be blank": "El id de ticket no puede quedar en blanco", "Weekday cannot be blank": "El día de la semana no puede quedar en blanco", "You can't delete a confirmed order": "No puedes borrar un pedido confirmado", - "Can't create stowaway for this ticket": "No se puede crear un polizon para este ticket" + "Can't create stowaway for this ticket": "No se puede crear un polizon para este ticket", + "Value has an invalid format": "El valor tiene un formato incorrecto" } \ No newline at end of file diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 25b9d7d354..0a3efc9581 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -150,6 +150,16 @@ module.exports = Self => { done(); } + Self.validateBinded('socialName', isAlpha, { + message: 'Value has an invalid format' + }); + + function isAlpha(value) { + const regexp = new RegExp(/^[a-zA-Z\s]*$/); + + return regexp.test(value); + } + Self.observe('before save', async function(ctx) { let changes = ctx.data || ctx.instance; let orgData = ctx.currentInstance; diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 061ee92f12..ceae68fb7f 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -12,7 +12,9 @@ vn-two vn-focus label="Social name" - field="$ctrl.client.socialName"> + model="$ctrl.client.socialName" + rule="client.socialName" + info="You can use letters and spaces">