From 8fad522a3e78da01b1afd659c584662d54c2ed0e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 19 Aug 2024 12:45:06 +0200 Subject: [PATCH 1/9] feat(salix): refs #7677 #7677 return more postcode fields --- modules/client/back/models/address.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/client/back/models/address.js b/modules/client/back/models/address.js index 4a93b5d5c..7011008a4 100644 --- a/modules/client/back/models/address.js +++ b/modules/client/back/models/address.js @@ -43,8 +43,14 @@ module.exports = Self => { include: [{ relation: 'province', scope: { - fields: ['id', 'name'] - } + fields: ['id', 'name', 'countryFk'], + include: [ + { + relation: 'country', + scope: {fields: ['id', 'name']}, + }, + ], + }, }, { relation: 'agencyMode', scope: { From b5940114331cf5fe3aa07ea8b0624cd4c31a29d1 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 20 Aug 2024 07:01:13 +0200 Subject: [PATCH 2/9] feat(salix): refs #7677 #7677 return more postcode fields --- back/methods/postcode/filter.js | 2 ++ db/dump/fixtures.after.sql | 4 ++-- db/dump/fixtures.before.sql | 1 + db/routines/vn/procedures/client_userDisable.sql | 6 +++--- loopback/locale/es.json | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index f350b1ea9..8f47b4a93 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -47,6 +47,8 @@ module.exports = Self => { let stmt; stmt = new ParameterizedSQL(` SELECT + CONCAT_WS('_', pc.code, pc.townFk, t.provinceFk, + p.countryFk) id, pc.townFk, t.provinceFk, p.countryFk, diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index 59730d592..5489d2dd2 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -255,7 +255,7 @@ INSERT INTO vn.operator (workerFk, numberOfWagons, trainFk, itemPackingTypeFk, w (9, 1, 1, 'V', 1); */ -- XXX: web -/* #5483 + INSERT INTO `hedera`.`config` (`cookieLife`, `defaultForm`) VALUES (15,'cms/home'); @@ -274,7 +274,7 @@ UPDATE `vn`.`agencyMode` SET `description` = `name`; INSERT INTO `hedera`.`tpvConfig` (currency, terminal, transactionType, maxAmount, employeeFk, `url`, testMode, testUrl, testKey, merchantUrl) VALUES (978, 1, 0, 2000, 9, 'https://sis.redsys.es/sis/realizarPago', 0, 'https://sis-t.redsys.es:25443/sis/realizarPago', 'sq7HjrUOBfKmC576ILgskD5srU870gJ7', NULL); -*/ + INSERT INTO hedera.tpvMerchantEnable (merchantFk, companyFk) VALUES (1, 442); diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 6563292dd..ca2468d5e 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -364,6 +364,7 @@ INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`) ('46460', 2, 6), ('46680', 3, 6), ('46600', 4, 7), + ('46600',1, 6), ('EC170150', 5, 8); INSERT INTO `vn`.`clientType`(`code`, `type`) diff --git a/db/routines/vn/procedures/client_userDisable.sql b/db/routines/vn/procedures/client_userDisable.sql index 779ffd688..c0977bc62 100644 --- a/db/routines/vn/procedures/client_userDisable.sql +++ b/db/routines/vn/procedures/client_userDisable.sql @@ -20,15 +20,15 @@ BEGIN WHERE c.typeFk = 'normal' AND a.id IS NULL AND u.active - AND c.created < util.VN_CURDATE() - INTERVAL vMonths MONTH + AND c.created < util.VN_CURDATE() - INTERVAL vMonths MONTH AND NOT u.role = (SELECT id FROM `role` WHERE name = 'supplier') AND u.id NOT IN ( SELECT DISTINCT c.id FROM client c LEFT JOIN ticket t ON t.clientFk = c.id WHERE c.salesPersonFk IS NOT NULL - OR t.created > util.VN_CURDATE() - INTERVAL vMonths MONTH - OR shipped > util.VN_CURDATE() - INTERVAL vMonths MONTH + OR t.created > util.VN_CURDATE() - INTERVAL vMonths MONTH + OR shipped > util.VN_CURDATE() - INTERVAL vMonths MONTH ); END$$ DELIMITER ; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 377691ae6..5d9963833 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -370,5 +370,6 @@ "CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos", "The sale not exists in the item shelving": "La venta no existe en la estantería del artículo", "The entry not have stickers": "La entrada no tiene etiquetas", - "Too many records": "Demasiados registros" + "Too many records": "Demasiados registros", + "CONSTRAINT `zone.price` failed for `vn`.`zone`": "CONSTRAINT `zone.price` failed for `vn`.`zone`" } \ No newline at end of file From 71eb44d0833b1d37b8c72e51f23cc9ec2a35c0b0 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 9 Sep 2024 09:58:20 +0200 Subject: [PATCH 3/9] refactor(vnUser): refs #7792 use twoFactorFk and add foreignKey --- back/methods/vn-user/sign-in.js | 8 +++--- back/methods/vn-user/specs/sign-in.spec.js | 2 +- back/methods/vn-user/update-user.js | 8 +++--- back/methods/vn-user/validate-auth.js | 2 +- back/models/vn-user.json | 11 +++++--- db/.pullinfo.json | 2 +- .../vn/triggers/department_afterUpdate.sql | 4 +-- .../11218-pinkRaphis/00-firstScript.sql | 27 +++++++++++++++++++ .../components/change-password/index.html | 2 +- .../back/methods/account/change-password.js | 4 +-- .../account/specs/change-password.spec.js | 2 +- modules/account/back/model-config.json | 5 +++- .../account/back/models/two-factor-type.json | 26 ++++++++++++++++++ myt.config.yml | 3 ++- 14 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 db/versions/11218-pinkRaphis/00-firstScript.sql create mode 100644 modules/account/back/models/two-factor-type.json diff --git a/back/methods/vn-user/sign-in.js b/back/methods/vn-user/sign-in.js index 775970d55..d74c486c3 100644 --- a/back/methods/vn-user/sign-in.js +++ b/back/methods/vn-user/sign-in.js @@ -33,7 +33,7 @@ module.exports = Self => { const where = Self.userUses(user); const vnUser = await Self.findOne({ - fields: ['id', 'name', 'password', 'active', 'email', 'passExpired', 'twoFactor'], + fields: ['id', 'name', 'password', 'active', 'email', 'passExpired', 'twoFactorFk'], where }, myOptions); @@ -46,7 +46,7 @@ module.exports = Self => { await Self.sendTwoFactor(ctx, vnUser, myOptions); await Self.passExpired(vnUser, myOptions); - if (vnUser.twoFactor) + if (vnUser.twoFactorFk) throw new ForbiddenError(null, 'REQUIRES_2FA'); } return Self.validateLogin(user, password, ctx); @@ -58,13 +58,13 @@ module.exports = Self => { if (vnUser.passExpired && vnUser.passExpired.getTime() <= today.getTime()) { const err = new UserError('Pass expired', 'passExpired'); - err.details = {userId: vnUser.id, twoFactor: vnUser.twoFactor ? true : false}; + err.details = {userId: vnUser.id, twoFactorFk: vnUser.twoFactorFk ? true : false}; throw err; } }; Self.sendTwoFactor = async(ctx, vnUser, myOptions) => { - if (vnUser.twoFactor === 'email') { + if (vnUser.twoFactorFk === 'email') { const $ = Self.app.models; const min = 100000; diff --git a/back/methods/vn-user/specs/sign-in.spec.js b/back/methods/vn-user/specs/sign-in.spec.js index a14dd301e..331173d38 100644 --- a/back/methods/vn-user/specs/sign-in.spec.js +++ b/back/methods/vn-user/specs/sign-in.spec.js @@ -70,7 +70,7 @@ describe('VnUser Sign-in()', () => { let error; try { const options = {transaction: tx}; - await employee.updateAttribute('twoFactor', 'email', options); + await employee.updateAttribute('twoFactorFk', 'email', options); await VnUser.signIn(unAuthCtx, 'employee', 'nightmare', options); await tx.rollback(); diff --git a/back/methods/vn-user/update-user.js b/back/methods/vn-user/update-user.js index 202b01c65..b0ac40192 100644 --- a/back/methods/vn-user/update-user.js +++ b/back/methods/vn-user/update-user.js @@ -25,8 +25,8 @@ module.exports = Self => { type: 'string', description: 'The user lang' }, { - arg: 'twoFactor', - type: 'string', + arg: 'twoFactorFk', + type: 'any', description: 'The user twoFactor' } ], @@ -36,8 +36,8 @@ module.exports = Self => { } }); - Self.updateUser = async(ctx, id, name, nickname, email, lang, twoFactor) => { + Self.updateUser = async(ctx, id, name, nickname, email, lang, twoFactorFk) => { await Self.userSecurity(ctx, id); - await Self.upsertWithWhere({id}, {name, nickname, email, lang, twoFactor}); + await Self.upsertWithWhere({id}, {name, nickname, email, lang, twoFactorFk}); }; }; diff --git a/back/methods/vn-user/validate-auth.js b/back/methods/vn-user/validate-auth.js index 8fb8b4923..56f0f9c5f 100644 --- a/back/methods/vn-user/validate-auth.js +++ b/back/methods/vn-user/validate-auth.js @@ -55,7 +55,7 @@ module.exports = Self => { throw new UserError('Invalid or expired verification code'); const user = await Self.findById(authCode.userFk, { - fields: ['name', 'twoFactor'] + fields: ['name', 'twoFactorFk'] }, myOptions); if (user.name.toLowerCase() !== username.toLowerCase()) diff --git a/back/models/vn-user.json b/back/models/vn-user.json index 415aa6810..b107a8e52 100644 --- a/back/models/vn-user.json +++ b/back/models/vn-user.json @@ -58,9 +58,6 @@ }, "passExpired": { "type": "date" - }, - "twoFactor": { - "type": "string" } }, "relations": { @@ -89,6 +86,11 @@ "type": "hasOne", "model": "UserConfig", "foreignKey": "userFk" + }, + "twoFactor": { + "type": "belongsTo", + "model": "TwoFactorType", + "foreignKey": "twoFactorFk" } }, "acls": [ @@ -165,7 +167,8 @@ "hasGrant", "realm", "email", - "emailVerified" + "emailVerified", + "twoFactorFk" ] } } diff --git a/db/.pullinfo.json b/db/.pullinfo.json index 27d2c7535..5b75584d1 100644 --- a/db/.pullinfo.json +++ b/db/.pullinfo.json @@ -9,7 +9,7 @@ }, "vn": { "view": { - "expeditionPallet_Print": "ced2b84a114fcb99fce05f0c34f4fc03f3fa387bef92621be1bc306608a84345" + "expeditionPallet_Print": "99f75145ac2e7b612a6d71e74b6e55f194a465780fd9875a15eb01e6596b447e" } } } diff --git a/db/routines/vn/triggers/department_afterUpdate.sql b/db/routines/vn/triggers/department_afterUpdate.sql index 559fad9a3..216af0e68 100644 --- a/db/routines/vn/triggers/department_afterUpdate.sql +++ b/db/routines/vn/triggers/department_afterUpdate.sql @@ -7,10 +7,10 @@ BEGIN UPDATE vn.department_recalc SET isChanged = TRUE; END IF; - IF !(OLD.twoFactor <=> NEW.twoFactor) THEN + IF !(OLD.twoFactorFk <=> NEW.twoFactorFk) THEN UPDATE account.user u JOIN vn.workerDepartment wd ON wd.workerFk = u.id - SET u.twoFactor = NEW.twoFactor + SET u.twoFactorFk = NEW.twoFactorFk WHERE wd.departmentFk = NEW.id; END IF; END$$ diff --git a/db/versions/11218-pinkRaphis/00-firstScript.sql b/db/versions/11218-pinkRaphis/00-firstScript.sql new file mode 100644 index 000000000..21bbe3bfc --- /dev/null +++ b/db/versions/11218-pinkRaphis/00-firstScript.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE TABLE account.twoFactorType ( + `code` varchar(20) NOT NULL, + `description` varchar(255) NOT NULL, + PRIMARY KEY (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE account.user ADD twoFactorFk varchar(20) NULL; +ALTER TABLE account.user ADD CONSTRAINT user_twoFactor_fk FOREIGN KEY (twoFactorFk) REFERENCES account.twoFactorType(code) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.department ADD twoFactorFk varchar(20) NULL; +ALTER TABLE vn.department ADD CONSTRAINT department_twoFactor_fk FOREIGN KEY (twoFactorFk) REFERENCES account.twoFactorType(code) ON DELETE CASCADE ON UPDATE CASCADE; + +INSERT INTO account.twoFactorType (code, description) + VALUES('email', 'Envia un código por email'); + +UPDATE account.`user` u + JOIN account.`user` u2 ON u.id = u2.id + SET u.twoFactorFk = u.twoFactor + WHERE u2.twoFactor IS NOT NULL; + +UPDATE vn.`department` d + JOIN vn.`department` d2 ON d.id = d2.id + SET d.twoFactorFk = d.twoFactor + WHERE d2.twoFactor IS NOT NULL; + +ALTER TABLE account.user CHANGE twoFactor twoFactor__ enum('email') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'Deprecated 2024-09-09'; +ALTER TABLE vn.department CHANGE twoFactor twoFactor__ enum('email') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'Deprecated 2024-09-09'; diff --git a/front/salix/components/change-password/index.html b/front/salix/components/change-password/index.html index 04f66976e..9021c51b2 100644 --- a/front/salix/components/change-password/index.html +++ b/front/salix/components/change-password/index.html @@ -22,7 +22,7 @@ autocomplete="false"> { Object.assign(myOptions, options); const {VnUser} = Self.app.models; - const user = await VnUser.findById(userId, {fields: ['name', 'twoFactor']}, myOptions); + const user = await VnUser.findById(userId, {fields: ['name', 'twoFactorFk']}, myOptions); await user.hasPassword(oldPassword); if (oldPassword == newPassword) throw new UserError(`You can not use the same password`); - if (user.twoFactor) + if (user.twoFactorFk) await VnUser.validateCode(user.name, code, myOptions); await VnUser.changePassword(userId, oldPassword, newPassword, myOptions); diff --git a/modules/account/back/methods/account/specs/change-password.spec.js b/modules/account/back/methods/account/specs/change-password.spec.js index c79960212..f3573f41c 100644 --- a/modules/account/back/methods/account/specs/change-password.spec.js +++ b/modules/account/back/methods/account/specs/change-password.spec.js @@ -75,7 +75,7 @@ describe('account changePassword()', () => { await models.VnUser.updateAll( {id: 70}, { - twoFactor: 'email', + twoFactorFk: 'email', passExpired: yesterday } , options); diff --git a/modules/account/back/model-config.json b/modules/account/back/model-config.json index 0cd43d0ce..d79d5de45 100644 --- a/modules/account/back/model-config.json +++ b/modules/account/back/model-config.json @@ -1,4 +1,7 @@ { + "Account": { + "dataSource": "vn" + }, "AccountConfig": { "dataSource": "vn" }, @@ -47,7 +50,7 @@ "SipConfig": { "dataSource": "vn" }, - "Account": { + "TwoFactorType": { "dataSource": "vn" }, "UserLog": { diff --git a/modules/account/back/models/two-factor-type.json b/modules/account/back/models/two-factor-type.json new file mode 100644 index 000000000..ce4a99858 --- /dev/null +++ b/modules/account/back/models/two-factor-type.json @@ -0,0 +1,26 @@ +{ + "name": "TwoFactorType", + "base": "VnModel", + "options": { + "mysql": { + "table": "account.twoFactorType" + } + }, + "properties": { + "code": { + "type": "string", + "id": true + }, + "description": { + "type": "string" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} diff --git a/myt.config.yml b/myt.config.yml index ffa4188b2..87407bac3 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -38,6 +38,7 @@ fixtures: - userPassword - accountConfig - mailConfig + - twoFactorType salix: - ACL - fieldAcl @@ -393,4 +394,4 @@ localFixtures: - zoneExclusionGeo - zoneGeo - zoneIncluded - - zoneWarehouse \ No newline at end of file + - zoneWarehouse From 2e32dfddc413156f88a97738f7e91dbf63862d46 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 17 Sep 2024 11:43:28 +0200 Subject: [PATCH 4/9] perf(salix): refs #7677 #7677 restore files --- db/dump/fixtures.after.sql | 4 ++-- db/routines/vn/procedures/client_userDisable.sql | 6 +++--- loopback/locale/es.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index 5489d2dd2..59730d592 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -255,7 +255,7 @@ INSERT INTO vn.operator (workerFk, numberOfWagons, trainFk, itemPackingTypeFk, w (9, 1, 1, 'V', 1); */ -- XXX: web - +/* #5483 INSERT INTO `hedera`.`config` (`cookieLife`, `defaultForm`) VALUES (15,'cms/home'); @@ -274,7 +274,7 @@ UPDATE `vn`.`agencyMode` SET `description` = `name`; INSERT INTO `hedera`.`tpvConfig` (currency, terminal, transactionType, maxAmount, employeeFk, `url`, testMode, testUrl, testKey, merchantUrl) VALUES (978, 1, 0, 2000, 9, 'https://sis.redsys.es/sis/realizarPago', 0, 'https://sis-t.redsys.es:25443/sis/realizarPago', 'sq7HjrUOBfKmC576ILgskD5srU870gJ7', NULL); - +*/ INSERT INTO hedera.tpvMerchantEnable (merchantFk, companyFk) VALUES (1, 442); diff --git a/db/routines/vn/procedures/client_userDisable.sql b/db/routines/vn/procedures/client_userDisable.sql index e769114fb..1a7c9846b 100644 --- a/db/routines/vn/procedures/client_userDisable.sql +++ b/db/routines/vn/procedures/client_userDisable.sql @@ -20,15 +20,15 @@ BEGIN WHERE c.typeFk = 'normal' AND a.id IS NULL AND u.active - AND c.created < util.VN_CURDATE() - INTERVAL vMonths MONTH + AND c.created < util.VN_CURDATE() - INTERVAL vMonths MONTH AND NOT u.role = (SELECT id FROM `role` WHERE name = 'supplier') AND u.id NOT IN ( SELECT DISTINCT c.id FROM client c LEFT JOIN ticket t ON t.clientFk = c.id WHERE c.salesPersonFk IS NOT NULL - OR t.created > util.VN_CURDATE() - INTERVAL vMonths MONTH - OR shipped > util.VN_CURDATE() - INTERVAL vMonths MONTH + OR t.created > util.VN_CURDATE() - INTERVAL vMonths MONTH + OR shipped > util.VN_CURDATE() - INTERVAL vMonths MONTH ); END$$ DELIMITER ; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index eb48b0646..1093fe326 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -378,4 +378,4 @@ "There is already a tray with the same height": "Ya existe una bandeja con la misma altura", "The height must be greater than 50cm": "La altura debe ser superior a 50cm", "The maximum height of the wagon is 200cm": "La altura máxima es 200cm" -} +} \ No newline at end of file From f962b2e38b0e365f6dba24b396d684ae68f36899 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 17 Sep 2024 11:44:34 +0200 Subject: [PATCH 5/9] perf(salix): refs #7677 #7677 restore files because unnecessary change --- back/methods/postcode/filter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index 8f47b4a93..f350b1ea9 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -47,8 +47,6 @@ module.exports = Self => { let stmt; stmt = new ParameterizedSQL(` SELECT - CONCAT_WS('_', pc.code, pc.townFk, t.provinceFk, - p.countryFk) id, pc.townFk, t.provinceFk, p.countryFk, From 7cd8e535f0fc85deedb6ff66e28f182fa848564a Mon Sep 17 00:00:00 2001 From: ivanm Date: Tue, 17 Sep 2024 16:19:09 +0200 Subject: [PATCH 6/9] refactor: refs #7934 Delete vn.MIDNIGHT function --- db/routines/vn/functions/MIDNIGHT.sql | 8 ----- db/routines/vn/functions/routeProposal_.sql | 30 ------------------- .../vn/procedures/itemShelvingProblem.sql | 2 +- db/routines/vn/views/ticketStateToday.sql | 2 +- 4 files changed, 2 insertions(+), 40 deletions(-) delete mode 100644 db/routines/vn/functions/MIDNIGHT.sql delete mode 100644 db/routines/vn/functions/routeProposal_.sql diff --git a/db/routines/vn/functions/MIDNIGHT.sql b/db/routines/vn/functions/MIDNIGHT.sql deleted file mode 100644 index d40734fcf..000000000 --- a/db/routines/vn/functions/MIDNIGHT.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`MIDNIGHT`(vDate DATE) - RETURNS datetime - DETERMINISTIC -BEGIN - RETURN TIMESTAMP(vDate,'23:59:59'); -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/routeProposal_.sql b/db/routines/vn/functions/routeProposal_.sql deleted file mode 100644 index a307d8fc0..000000000 --- a/db/routines/vn/functions/routeProposal_.sql +++ /dev/null @@ -1,30 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`routeProposal_`(vTicketFk INT) - RETURNS int(11) - NOT DETERMINISTIC - READS SQL DATA -BEGIN - - DECLARE vRouteFk INT; - DECLARE vAddressFk INT; - DECLARE vShipped DATETIME; - - SELECT addressFk, date(shipped) INTO vAddressFk, vShipped - FROM vn.ticket - WHERE id = vTicketFk; - - SELECT routeFk INTO vRouteFk - FROM - (SELECT t.routeFk, sum(af.friendship) friendshipSum - FROM vn.ticket t - JOIN cache.addressFriendship af ON af.addressFk2 = t.addressFk AND af.addressFk1 = vAddressFk - WHERE t.shipped BETWEEN vShipped and MIDNIGHT(vShipped) - AND t.routeFk - GROUP BY routeFk - ORDER BY friendshipSum DESC - ) sub - LIMIT 1; - - RETURN vRouteFk; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingProblem.sql b/db/routines/vn/procedures/itemShelvingProblem.sql index bb4725434..06c7a376c 100644 --- a/db/routines/vn/procedures/itemShelvingProblem.sql +++ b/db/routines/vn/procedures/itemShelvingProblem.sql @@ -38,7 +38,7 @@ BEGIN AND IFNULL(sub3.transit,0) < s.quantity AND s.isPicked = FALSE AND s.reserved = FALSE - AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE()) + AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() AND tst.isPreviousPreparable = TRUE AND t.warehouseFk = vWarehouseFk AND iss.sectorFk = vSectorFk diff --git a/db/routines/vn/views/ticketStateToday.sql b/db/routines/vn/views/ticketStateToday.sql index 0c9e01188..8c11fcc87 100644 --- a/db/routines/vn/views/ticketStateToday.sql +++ b/db/routines/vn/views/ticketStateToday.sql @@ -13,4 +13,4 @@ FROM ( `vn`.`ticketState` `ts` JOIN `vn`.`ticket` `t` ON(`t`.`id` = `ts`.`ticketFk`) ) -WHERE `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `MIDNIGHT`(`util`.`VN_CURDATE`()) +WHERE `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `util`.`midnight`() From 829ecba2ef57050e54369a4bce6e4c123c3a15a1 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 Sep 2024 08:30:05 +0200 Subject: [PATCH 7/9] refactor: refs #7792 revert TwoFactorType --- back/methods/vn-user/sign-in.js | 8 +++--- back/methods/vn-user/specs/sign-in.spec.js | 2 +- back/methods/vn-user/update-user.js | 8 +++--- back/methods/vn-user/validate-auth.js | 2 +- back/models/vn-user.json | 10 +++---- .../vn/triggers/department_afterUpdate.sql | 4 +-- .../11218-pinkRaphis/00-firstScript.sql | 12 ++++----- .../components/change-password/index.html | 2 +- .../back/methods/account/change-password.js | 4 +-- .../account/specs/change-password.spec.js | 2 +- modules/account/back/model-config.json | 3 --- .../account/back/models/two-factor-type.json | 26 ------------------- myt.config.yml | 1 - 13 files changed, 26 insertions(+), 58 deletions(-) delete mode 100644 modules/account/back/models/two-factor-type.json diff --git a/back/methods/vn-user/sign-in.js b/back/methods/vn-user/sign-in.js index d74c486c3..775970d55 100644 --- a/back/methods/vn-user/sign-in.js +++ b/back/methods/vn-user/sign-in.js @@ -33,7 +33,7 @@ module.exports = Self => { const where = Self.userUses(user); const vnUser = await Self.findOne({ - fields: ['id', 'name', 'password', 'active', 'email', 'passExpired', 'twoFactorFk'], + fields: ['id', 'name', 'password', 'active', 'email', 'passExpired', 'twoFactor'], where }, myOptions); @@ -46,7 +46,7 @@ module.exports = Self => { await Self.sendTwoFactor(ctx, vnUser, myOptions); await Self.passExpired(vnUser, myOptions); - if (vnUser.twoFactorFk) + if (vnUser.twoFactor) throw new ForbiddenError(null, 'REQUIRES_2FA'); } return Self.validateLogin(user, password, ctx); @@ -58,13 +58,13 @@ module.exports = Self => { if (vnUser.passExpired && vnUser.passExpired.getTime() <= today.getTime()) { const err = new UserError('Pass expired', 'passExpired'); - err.details = {userId: vnUser.id, twoFactorFk: vnUser.twoFactorFk ? true : false}; + err.details = {userId: vnUser.id, twoFactor: vnUser.twoFactor ? true : false}; throw err; } }; Self.sendTwoFactor = async(ctx, vnUser, myOptions) => { - if (vnUser.twoFactorFk === 'email') { + if (vnUser.twoFactor === 'email') { const $ = Self.app.models; const min = 100000; diff --git a/back/methods/vn-user/specs/sign-in.spec.js b/back/methods/vn-user/specs/sign-in.spec.js index 331173d38..a14dd301e 100644 --- a/back/methods/vn-user/specs/sign-in.spec.js +++ b/back/methods/vn-user/specs/sign-in.spec.js @@ -70,7 +70,7 @@ describe('VnUser Sign-in()', () => { let error; try { const options = {transaction: tx}; - await employee.updateAttribute('twoFactorFk', 'email', options); + await employee.updateAttribute('twoFactor', 'email', options); await VnUser.signIn(unAuthCtx, 'employee', 'nightmare', options); await tx.rollback(); diff --git a/back/methods/vn-user/update-user.js b/back/methods/vn-user/update-user.js index b0ac40192..202b01c65 100644 --- a/back/methods/vn-user/update-user.js +++ b/back/methods/vn-user/update-user.js @@ -25,8 +25,8 @@ module.exports = Self => { type: 'string', description: 'The user lang' }, { - arg: 'twoFactorFk', - type: 'any', + arg: 'twoFactor', + type: 'string', description: 'The user twoFactor' } ], @@ -36,8 +36,8 @@ module.exports = Self => { } }); - Self.updateUser = async(ctx, id, name, nickname, email, lang, twoFactorFk) => { + Self.updateUser = async(ctx, id, name, nickname, email, lang, twoFactor) => { await Self.userSecurity(ctx, id); - await Self.upsertWithWhere({id}, {name, nickname, email, lang, twoFactorFk}); + await Self.upsertWithWhere({id}, {name, nickname, email, lang, twoFactor}); }; }; diff --git a/back/methods/vn-user/validate-auth.js b/back/methods/vn-user/validate-auth.js index 56f0f9c5f..8fb8b4923 100644 --- a/back/methods/vn-user/validate-auth.js +++ b/back/methods/vn-user/validate-auth.js @@ -55,7 +55,7 @@ module.exports = Self => { throw new UserError('Invalid or expired verification code'); const user = await Self.findById(authCode.userFk, { - fields: ['name', 'twoFactorFk'] + fields: ['name', 'twoFactor'] }, myOptions); if (user.name.toLowerCase() !== username.toLowerCase()) diff --git a/back/models/vn-user.json b/back/models/vn-user.json index b107a8e52..8c49c8db9 100644 --- a/back/models/vn-user.json +++ b/back/models/vn-user.json @@ -58,6 +58,9 @@ }, "passExpired": { "type": "date" + }, + "twoFactor": { + "type": "string" } }, "relations": { @@ -86,11 +89,6 @@ "type": "hasOne", "model": "UserConfig", "foreignKey": "userFk" - }, - "twoFactor": { - "type": "belongsTo", - "model": "TwoFactorType", - "foreignKey": "twoFactorFk" } }, "acls": [ @@ -168,7 +166,7 @@ "realm", "email", "emailVerified", - "twoFactorFk" + "twoFactor" ] } } diff --git a/db/routines/vn/triggers/department_afterUpdate.sql b/db/routines/vn/triggers/department_afterUpdate.sql index 216af0e68..559fad9a3 100644 --- a/db/routines/vn/triggers/department_afterUpdate.sql +++ b/db/routines/vn/triggers/department_afterUpdate.sql @@ -7,10 +7,10 @@ BEGIN UPDATE vn.department_recalc SET isChanged = TRUE; END IF; - IF !(OLD.twoFactorFk <=> NEW.twoFactorFk) THEN + IF !(OLD.twoFactor <=> NEW.twoFactor) THEN UPDATE account.user u JOIN vn.workerDepartment wd ON wd.workerFk = u.id - SET u.twoFactorFk = NEW.twoFactorFk + SET u.twoFactor = NEW.twoFactor WHERE wd.departmentFk = NEW.id; END IF; END$$ diff --git a/db/versions/11218-pinkRaphis/00-firstScript.sql b/db/versions/11218-pinkRaphis/00-firstScript.sql index 21bbe3bfc..8efa18cd0 100644 --- a/db/versions/11218-pinkRaphis/00-firstScript.sql +++ b/db/versions/11218-pinkRaphis/00-firstScript.sql @@ -4,23 +4,23 @@ CREATE OR REPLACE TABLE account.twoFactorType ( PRIMARY KEY (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -ALTER TABLE account.user ADD twoFactorFk varchar(20) NULL; -ALTER TABLE account.user ADD CONSTRAINT user_twoFactor_fk FOREIGN KEY (twoFactorFk) REFERENCES account.twoFactorType(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE account.user ADD twoFactor varchar(20) NULL; +ALTER TABLE account.user ADD CONSTRAINT user_twoFactor_fk FOREIGN KEY (twoFactor) REFERENCES account.twoFactorType(code) ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE vn.department ADD twoFactorFk varchar(20) NULL; -ALTER TABLE vn.department ADD CONSTRAINT department_twoFactor_fk FOREIGN KEY (twoFactorFk) REFERENCES account.twoFactorType(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.department ADD twoFactor varchar(20) NULL; +ALTER TABLE vn.department ADD CONSTRAINT department_twoFactor_fk FOREIGN KEY (twoFactor) REFERENCES account.twoFactorType(code) ON DELETE CASCADE ON UPDATE CASCADE; INSERT INTO account.twoFactorType (code, description) VALUES('email', 'Envia un código por email'); UPDATE account.`user` u JOIN account.`user` u2 ON u.id = u2.id - SET u.twoFactorFk = u.twoFactor + SET u.twoFactor = u.twoFactor WHERE u2.twoFactor IS NOT NULL; UPDATE vn.`department` d JOIN vn.`department` d2 ON d.id = d2.id - SET d.twoFactorFk = d.twoFactor + SET d.twoFactor = d.twoFactor WHERE d2.twoFactor IS NOT NULL; ALTER TABLE account.user CHANGE twoFactor twoFactor__ enum('email') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'Deprecated 2024-09-09'; diff --git a/front/salix/components/change-password/index.html b/front/salix/components/change-password/index.html index 9021c51b2..04f66976e 100644 --- a/front/salix/components/change-password/index.html +++ b/front/salix/components/change-password/index.html @@ -22,7 +22,7 @@ autocomplete="false"> { Object.assign(myOptions, options); const {VnUser} = Self.app.models; - const user = await VnUser.findById(userId, {fields: ['name', 'twoFactorFk']}, myOptions); + const user = await VnUser.findById(userId, {fields: ['name', 'twoFactor']}, myOptions); await user.hasPassword(oldPassword); if (oldPassword == newPassword) throw new UserError(`You can not use the same password`); - if (user.twoFactorFk) + if (user.twoFactor) await VnUser.validateCode(user.name, code, myOptions); await VnUser.changePassword(userId, oldPassword, newPassword, myOptions); diff --git a/modules/account/back/methods/account/specs/change-password.spec.js b/modules/account/back/methods/account/specs/change-password.spec.js index f3573f41c..c79960212 100644 --- a/modules/account/back/methods/account/specs/change-password.spec.js +++ b/modules/account/back/methods/account/specs/change-password.spec.js @@ -75,7 +75,7 @@ describe('account changePassword()', () => { await models.VnUser.updateAll( {id: 70}, { - twoFactorFk: 'email', + twoFactor: 'email', passExpired: yesterday } , options); diff --git a/modules/account/back/model-config.json b/modules/account/back/model-config.json index d79d5de45..cfec1fbe4 100644 --- a/modules/account/back/model-config.json +++ b/modules/account/back/model-config.json @@ -50,9 +50,6 @@ "SipConfig": { "dataSource": "vn" }, - "TwoFactorType": { - "dataSource": "vn" - }, "UserLog": { "dataSource": "vn" }, diff --git a/modules/account/back/models/two-factor-type.json b/modules/account/back/models/two-factor-type.json deleted file mode 100644 index ce4a99858..000000000 --- a/modules/account/back/models/two-factor-type.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "TwoFactorType", - "base": "VnModel", - "options": { - "mysql": { - "table": "account.twoFactorType" - } - }, - "properties": { - "code": { - "type": "string", - "id": true - }, - "description": { - "type": "string" - } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] -} diff --git a/myt.config.yml b/myt.config.yml index 87407bac3..dcda2d04b 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -38,7 +38,6 @@ fixtures: - userPassword - accountConfig - mailConfig - - twoFactorType salix: - ACL - fieldAcl From c75cc87129039f54f1969fdb3cbfc76b76c6ac7c Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 Sep 2024 08:31:26 +0200 Subject: [PATCH 8/9] refactor: refs #7792 revert TwoFactorType --- .../11218-pinkRaphis/00-firstScript.sql | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 db/versions/11218-pinkRaphis/00-firstScript.sql diff --git a/db/versions/11218-pinkRaphis/00-firstScript.sql b/db/versions/11218-pinkRaphis/00-firstScript.sql deleted file mode 100644 index 8efa18cd0..000000000 --- a/db/versions/11218-pinkRaphis/00-firstScript.sql +++ /dev/null @@ -1,27 +0,0 @@ -CREATE OR REPLACE TABLE account.twoFactorType ( - `code` varchar(20) NOT NULL, - `description` varchar(255) NOT NULL, - PRIMARY KEY (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -ALTER TABLE account.user ADD twoFactor varchar(20) NULL; -ALTER TABLE account.user ADD CONSTRAINT user_twoFactor_fk FOREIGN KEY (twoFactor) REFERENCES account.twoFactorType(code) ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE vn.department ADD twoFactor varchar(20) NULL; -ALTER TABLE vn.department ADD CONSTRAINT department_twoFactor_fk FOREIGN KEY (twoFactor) REFERENCES account.twoFactorType(code) ON DELETE CASCADE ON UPDATE CASCADE; - -INSERT INTO account.twoFactorType (code, description) - VALUES('email', 'Envia un código por email'); - -UPDATE account.`user` u - JOIN account.`user` u2 ON u.id = u2.id - SET u.twoFactor = u.twoFactor - WHERE u2.twoFactor IS NOT NULL; - -UPDATE vn.`department` d - JOIN vn.`department` d2 ON d.id = d2.id - SET d.twoFactor = d.twoFactor - WHERE d2.twoFactor IS NOT NULL; - -ALTER TABLE account.user CHANGE twoFactor twoFactor__ enum('email') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'Deprecated 2024-09-09'; -ALTER TABLE vn.department CHANGE twoFactor twoFactor__ enum('email') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'Deprecated 2024-09-09'; From e523b12536527d2b1ebfa71c473d2a217c676d67 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 Sep 2024 09:50:55 +0200 Subject: [PATCH 9/9] fix: refs #7792 enable null --- back/methods/vn-user/update-user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/vn-user/update-user.js b/back/methods/vn-user/update-user.js index 202b01c65..2bb390cf9 100644 --- a/back/methods/vn-user/update-user.js +++ b/back/methods/vn-user/update-user.js @@ -26,7 +26,7 @@ module.exports = Self => { description: 'The user lang' }, { arg: 'twoFactor', - type: 'string', + type: 'any', description: 'The user twoFactor' } ],