From 7367d1cdfeb5f5b4ba9114229ced38bd920e70c9 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 27 Jul 2023 14:41:53 +0200 Subject: [PATCH 1/9] refs #6013 fix: add await --- .../back/methods/worker-time-control/weeklyHourRecordEmail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index f440805592..3203dea827 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -51,7 +51,7 @@ module.exports = Self => { const salix = await models.Url.findOne({ where: { appName: 'salix', - environment: process.env.NODE_ENV || 'dev' + environment: process.env.NODE_ENV || 'development' } }, myOptions); @@ -61,7 +61,7 @@ module.exports = Self => { const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; ctx.args.url = url; - Self.sendTemplate(ctx, 'weekly-hour-record'); + await Self.sendTemplate(ctx, 'weekly-hour-record'); return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions); }; From 0054f2d82f04b3a26bbf341be66f499918ee8676 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 27 Jul 2023 15:07:10 +0200 Subject: [PATCH 2/9] refs #6013 fix: codigo no bloqueante --- .../methods/worker-time-control/sendMail.js | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index ab5e56a77f..13317fc65e 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -121,15 +121,18 @@ module.exports = Self => { `, [started, ended]); stmts.push(stmt); - stmt = new ParameterizedSQL(`INSERT INTO mail (receiver, subject, body) - SELECT CONCAT(u.name, '@verdnatura.es'), - CONCAT('Error registro de horas semana ', ?, ' año ', ?) , - CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) - FROM tmp.timeControlError tce - JOIN vn.workerTimeControl wtc ON wtc.id = tce.id - JOIN worker w ON w.id = wtc.userFK - JOIN account.user u ON u.id = w.bossFk - GROUP BY w.bossFk`, [args.week, args.year]); + stmt = new ParameterizedSQL(` + INSERT INTO mail (receiver, subject, body) + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT('Error registro de horas semana ', ?, ' año ', ?) , + CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', + GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + FROM tmp.timeControlError tce + JOIN vn.workerTimeControl wtc ON wtc.id = tce.id + JOIN worker w ON w.id = wtc.userFK + JOIN account.user u ON u.id = w.bossFk + GROUP BY w.bossFk + `, [args.week, args.year]); stmts.push(stmt); stmt = new ParameterizedSQL(` @@ -176,6 +179,7 @@ module.exports = Self => { const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); + console.log(days[index]); for (let day of days[index]) { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); @@ -371,7 +375,30 @@ module.exports = Self => { } } catch (e) { if (tx) await tx.rollback(); - throw e; + delete myOptions.transaction; + + const stmts = []; + let stmt; + stmt = new ParameterizedSQL(` + INSERT INTO mail (receiver, subject, body) + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT('Error registro de horas semana ', ?, ' año ', ?) , + CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', + GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + FROM worker w + JOIN account.user u ON u.id = w.bossFk + WHERE w.id = ? + GROUP BY w.bossFk + `, [args.week, args.year, day.workerFk]); + stmts.push(stmt); + + const sql = ParameterizedSQL.join(stmts, ';'); + await conn.executeStmt(sql); + + previousWorkerFk = day.workerFk; + previousReceiver = day.receiver; + + continue; } } From 251ed36eca664a9c015bcc15003d49dc39a774cc Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 28 Jul 2023 10:51:48 +0200 Subject: [PATCH 3/9] refs #6013 feat: mostrar error en el mail --- .../back/methods/worker-time-control/sendMail.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 13317fc65e..4988d1f464 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -179,7 +179,6 @@ module.exports = Self => { const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); - console.log(days[index]); for (let day of days[index]) { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); @@ -374,22 +373,18 @@ module.exports = Self => { delete myOptions.transaction; } } catch (e) { - if (tx) await tx.rollback(); - delete myOptions.transaction; - const stmts = []; let stmt; stmt = new ParameterizedSQL(` INSERT INTO mail (receiver, subject, body) SELECT CONCAT(u.name, '@verdnatura.es'), CONCAT('Error registro de horas semana ', ?, ' año ', ?) , - CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', - GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + CONCAT('No se ha podido enviar el registro de horas al empleado: ', + w.id, ' ', w.firstName, ' ', w.lastName, ' por el motivo: ', ?) FROM worker w JOIN account.user u ON u.id = w.bossFk WHERE w.id = ? - GROUP BY w.bossFk - `, [args.week, args.year, day.workerFk]); + `, [args.week, args.year, e.message, day.workerFk]); stmts.push(stmt); const sql = ParameterizedSQL.join(stmts, ';'); @@ -398,6 +393,9 @@ module.exports = Self => { previousWorkerFk = day.workerFk; previousReceiver = day.receiver; + if (tx) await tx.rollback(); + delete myOptions.transaction; + continue; } } From 4657bf4e433c9292d2604321d2f0dab865073cce Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 22 Aug 2023 14:58:26 +0200 Subject: [PATCH 4/9] refs #6143 refactor: ibanValidation with countryCode param --- loopback/util/validateIban.js | 3 ++- modules/client/back/models/client.js | 8 +++----- modules/supplier/back/models/supplier-account.js | 9 +++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/loopback/util/validateIban.js b/loopback/util/validateIban.js index 3ca09ef959..ed3e004260 100644 --- a/loopback/util/validateIban.js +++ b/loopback/util/validateIban.js @@ -1,6 +1,7 @@ -module.exports = function(iban) { +module.exports = function(iban, countryCode) { if (iban == null) return true; if (typeof iban != 'string') return false; + if (countryCode?.toLowerCase() != 'es') return true; iban = iban.toUpperCase(); iban = trim(iban); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 129924b784..bdf2f91b50 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -90,16 +90,14 @@ module.exports = Self => { }); async function ibanNeedsValidation(err, done) { + const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk); const filter = { fields: ['code'], - where: {id: this.countryFk} + where: {id: bankEntity.countryFk} }; const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code.toLowerCase() : null; - if (code != 'es') - return done(); - if (!validateIban(this.iban)) + if (!validateIban(this.iban, country?.code)) err(); done(); } diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js index 51da113ec3..7a9e144213 100644 --- a/modules/supplier/back/models/supplier-account.js +++ b/modules/supplier/back/models/supplier-account.js @@ -7,18 +7,15 @@ module.exports = Self => { }); async function ibanValidation(err, done) { - const supplier = await Self.app.models.Supplier.findById(this.supplierFk); + const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk); const filter = { fields: ['code'], - where: {id: supplier.countryFk} + where: {id: bankEntity.countryFk} }; const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code.toLowerCase() : null; - if (code != 'es') - return done(); - if (!validateIban(this.iban)) + if (!validateIban(this.iban, country?.code)) err(); done(); } From 470f511b3048b8bedebc18085afd148f73038668 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 24 Aug 2023 08:05:27 +0200 Subject: [PATCH 5/9] refs #5881 createRolAndGrantAcl --- db/changes/233601/00-createClaimReader.sql | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 db/changes/233601/00-createClaimReader.sql diff --git a/db/changes/233601/00-createClaimReader.sql b/db/changes/233601/00-createClaimReader.sql new file mode 100644 index 0000000000..10ab03d29b --- /dev/null +++ b/db/changes/233601/00-createClaimReader.sql @@ -0,0 +1,33 @@ +INSERT INTO `account`.`role` (`id`, `name`, `description`, `hasLogin`) + VALUES (122, 'claimViewer','Trabajadores que consulta las reclamaciones ',1); + +INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) + VALUES (35, 122); +INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) + VALUES (18, 122); +INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) + VALUES (41, 122); +INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) + VALUES (57, 122); + +DELETE FROM `salix`.`ACL` + WHERE `model`= 'claim' + AND `property` = 'filter'; +DELETE FROM `salix`.`ACL` + WHERE `model`= 'claim' + AND `property` = 'find'; +DELETE FROM `salix`.`ACL` + WHERE `model`= 'claim' + AND `property` = 'findById'; +DELETE FROM `salix`.`ACL` + WHERE `model`= 'claim' + AND `property` = 'getSummary'; + +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) + VALUES ('Claim','filter','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) + VALUES ('Claim','find','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) + VALUES ('Claim','findById','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) + VALUES ('Claim','getSummary','READ','ALLOW','ROLE','claimViewer'); From beeebbdf9c7522e7f9eaf1519001e815780ba313 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 24 Aug 2023 09:33:58 +0200 Subject: [PATCH 6/9] =?UTF-8?q?refs=20#6013=20refactor:=20siempre=20se=20c?= =?UTF-8?q?rea=20una=20tranacci=C3=B3n=20para=20cada=20dia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/worker-time-control/sendMail.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 4988d1f464..66fb7cc23e 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -180,10 +180,8 @@ module.exports = Self => { const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); for (let day of days[index]) { - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; try { workerFk = day.workerFk; if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null @@ -368,10 +366,7 @@ module.exports = Self => { previousReceiver = day.receiver; } - if (tx) { - await tx.commit(); - delete myOptions.transaction; - } + if (tx) await tx.commit(); } catch (e) { const stmts = []; let stmt; @@ -394,7 +389,6 @@ module.exports = Self => { previousReceiver = day.receiver; if (tx) await tx.rollback(); - delete myOptions.transaction; continue; } From 3694fcbbfb6c24d17538b0323efa764764e35c77 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 24 Aug 2023 10:04:32 +0200 Subject: [PATCH 7/9] refs #5881 fixCreateRol --- db/changes/233601/00-createClaimReader.sql | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/db/changes/233601/00-createClaimReader.sql b/db/changes/233601/00-createClaimReader.sql index 10ab03d29b..b1accf3299 100644 --- a/db/changes/233601/00-createClaimReader.sql +++ b/db/changes/233601/00-createClaimReader.sql @@ -1,33 +1,33 @@ INSERT INTO `account`.`role` (`id`, `name`, `description`, `hasLogin`) - VALUES (122, 'claimViewer','Trabajadores que consulta las reclamaciones ',1); + VALUES ('claimViewer','Trabajadores que consulta las reclamaciones ',1); INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) - VALUES (35, 122); -INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) - VALUES (18, 122); -INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) - VALUES (41, 122); -INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) - VALUES (57, 122); + SELECT `r`.`id`, `r2`.`id` + FROM `account`.`role` `r` + JOIN `account`.`role` `r2` ON `r2`.`name` = 'claimViewer' + WHERE `r`.`name` IN ( + 'salesPerson', + 'buyer', + 'deliveryBoss', + 'handmadeBoss' + ) DELETE FROM `salix`.`ACL` WHERE `model`= 'claim' - AND `property` = 'filter'; -DELETE FROM `salix`.`ACL` - WHERE `model`= 'claim' - AND `property` = 'find'; -DELETE FROM `salix`.`ACL` - WHERE `model`= 'claim' - AND `property` = 'findById'; -DELETE FROM `salix`.`ACL` - WHERE `model`= 'claim' - AND `property` = 'getSummary'; + AND `property` IN ( + 'filter', + 'find', + 'findById', + 'getSummary' + ); INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) - VALUES ('Claim','filter','READ','ALLOW','ROLE','claimViewer'); -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) - VALUES ('Claim','find','READ','ALLOW','ROLE','claimViewer'); -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) - VALUES ('Claim','findById','READ','ALLOW','ROLE','claimViewer'); -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) - VALUES ('Claim','getSummary','READ','ALLOW','ROLE','claimViewer'); + SELECT 'Claim',`property`,'READ','ALLOW','ROLE','claimViewer' + FROM `salix`.`ACL` + WHERE `property` IN ( + 'filter', + 'find', + 'findById', + 'getSummary' + ) + GROUP BY `property`; From c5006b6be685b23a96f1917f215f2c812385e03b Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 24 Aug 2023 11:31:12 +0200 Subject: [PATCH 8/9] refs #5881 insertAcl --- db/changes/233601/00-createClaimReader.sql | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/db/changes/233601/00-createClaimReader.sql b/db/changes/233601/00-createClaimReader.sql index b1accf3299..666bf232e3 100644 --- a/db/changes/233601/00-createClaimReader.sql +++ b/db/changes/233601/00-createClaimReader.sql @@ -22,12 +22,11 @@ DELETE FROM `salix`.`ACL` ); INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) - SELECT 'Claim',`property`,'READ','ALLOW','ROLE','claimViewer' - FROM `salix`.`ACL` - WHERE `property` IN ( - 'filter', - 'find', - 'findById', - 'getSummary' - ) - GROUP BY `property`; + VALUES ('Claim','filter','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) + VALUES ('Claim','find','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) + VALUES ('Claim','findById','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalid`) + VALUES ('Claim','getSummary','READ','ALLOW','ROLE','claimViewer'); + From f54a23922904e7afba8b5b69aff839769de337ff Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 25 Aug 2023 09:46:53 +0200 Subject: [PATCH 9/9] fixes #6143 fixes: this.bankEntityFk no existe --- loopback/util/specs/validateIban.spec.js | 44 ++++++++++++++----- modules/client/back/models/client.js | 3 ++ .../supplier/back/models/supplier-account.js | 3 ++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/loopback/util/specs/validateIban.spec.js b/loopback/util/specs/validateIban.spec.js index a5d08d4c4d..dd096c1b5e 100644 --- a/loopback/util/specs/validateIban.spec.js +++ b/loopback/util/specs/validateIban.spec.js @@ -1,21 +1,45 @@ const validateIban = require('../validateIban'); describe('IBAN validation', () => { - it('should return false for non-IBAN input', () => { - let isValid = validateIban('Pepinillos'); + it('should return false for invalid Spanish IBAN format', () => { + let isValid = validateIban('ES00 9999 0000 9999 0000 9999', 'ES'); expect(isValid).toBeFalsy(); }); - it('should return false for invalid spanish IBAN input', () => { - let isValid = validateIban('ES00 9999 0000 9999 0000 9999'); - - expect(isValid).toBeFalsy(); - }); - - it('should return true for valid spanish IBAN', () => { - let isValid = validateIban('ES91 2100 0418 4502 0005 1332'); + it('should return true for valid Spanish IBAN', () => { + let isValid = validateIban('ES91 2100 0418 4502 0005 1332', 'ES'); expect(isValid).toBeTruthy(); }); + + it('should return false for invalid Spanish IBAN with incorrect length', () => { + let isValid = validateIban('ES91210004184502000513', 'ES'); + + expect(isValid).toBeFalsy(); + }); + + it('should return false for invalid Spanish IBAN with incorrect module97 result', () => { + let isValid = validateIban('ES9121000418450200051331', 'ES'); + + expect(isValid).toBeFalsy(); + }); + + it('should return true for a non-Spanish countryCode', () => { + let isValid = validateIban('DE89370400440532013000', 'AT'); + + expect(isValid).toBeTruthy(); + }); + + it('should return true for null IBAN', () => { + let isValid = validateIban(null, 'ES'); + + expect(isValid).toBeTruthy(); + }); + + it('should return false for non-string IBAN', () => { + let isValid = validateIban(12345, 'ES'); + + expect(isValid).toBeFalsy(); + }); }); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index bdf2f91b50..8e720484ff 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -90,6 +90,9 @@ module.exports = Self => { }); async function ibanNeedsValidation(err, done) { + if (!this.bankEntityFk) + return done(); + const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk); const filter = { fields: ['code'], diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js index 7a9e144213..691e725808 100644 --- a/modules/supplier/back/models/supplier-account.js +++ b/modules/supplier/back/models/supplier-account.js @@ -7,6 +7,9 @@ module.exports = Self => { }); async function ibanValidation(err, done) { + if (!this.bankEntityFk) + return done(); + const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk); const filter = { fields: ['code'],