From 4ae06d4b6b22a846bf5ad422898c0fb29d0a6bc4 Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 25 Aug 2023 07:36:52 +0200 Subject: [PATCH 01/10] refs #6159 fixBusinessAfterInsert --- .../233601/00-updateAfterBusinnesInsert.sql | 42 +++++++++++++++++++ db/dump/fixtures.sql | 5 +++ 2 files changed, 47 insertions(+) create mode 100644 db/changes/233601/00-updateAfterBusinnesInsert.sql diff --git a/db/changes/233601/00-updateAfterBusinnesInsert.sql b/db/changes/233601/00-updateAfterBusinnesInsert.sql new file mode 100644 index 000000000..f2b5dc753 --- /dev/null +++ b/db/changes/233601/00-updateAfterBusinnesInsert.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_afterInsert` + AFTER INSERT ON `business` + FOR EACH ROW +BEGIN + CALL worker_updateBusiness(NEW.workerFk); + + IF ( + SELECT NOT active + FROM account.user + WHERE id = NEW.workerFk + ) THEN + UPDATE account.user + SET active = TRUE + WHERE id = NEW.workerFk; + END IF; + + IF ( + SELECT NOT COUNT(aa.id) + FROM account.mailAliasAccount aa + JOIN account.mailAlias ma ON ma.id = aa.mailAlias + WHERE aa.account = NEW.workerFk + AND ma.alias = 'general' + ) THEN + INSERT INTO account.mailAliasAccount (mailAlias, account) + SELECT id, NEW.workerFk + FROM account.mailAlias + WHERE alias = 'general'; + END IF; + + IF ( + SELECT NOT COUNT(account) + FROM account.mailForward + WHERE account = NEW.workerFk + ) THEN + INSERT INTO account.mailForward (account, forwardTo) + SELECT NEW.workerFk, email + FROM account.user + WHERE id = NEW.workerFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b01c07461..a3d76015f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1965,6 +1965,11 @@ INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) VALUES (1, 'General schedule', 40, 0); +INSERT INTO `account`.`account`(id) + SELECT u.id + FROM account.user u + LEFT JOIN account.account a ON a.id = u.id + WHERE a.id IS NULL; DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker From c06ee9c5b039e1048a72db7d80027474dd84e987 Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 25 Aug 2023 10:55:10 +0200 Subject: [PATCH 02/10] refs #6159 fixUserNoActiveOnNewBusiness --- db/dump/fixtures.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index a3d76015f..5ac355ea4 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1994,6 +1994,9 @@ INSERT INTO `vn`.`business` (`id`, `workerFk`, `companyCodeFk`, `started`, `ende DROP TEMPORARY TABLE IF EXISTS tmp.worker; +DELETE FROM `account`.`account` + WHERE id = 1105; + UPDATE `vn`.`business` SET `payedHolidays`= 8 WHERE `id`= 1106; From d14c49519e6ddb750cde49a68fa41e75c8bee01b Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 4 Sep 2023 13:16:35 +0200 Subject: [PATCH 03/10] refs #6159 fixSpec --- modules/client/back/methods/client/specs/setPassword.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/specs/setPassword.spec.js b/modules/client/back/methods/client/specs/setPassword.spec.js index 590172a02..6df527e70 100644 --- a/modules/client/back/methods/client/specs/setPassword.spec.js +++ b/modules/client/back/methods/client/specs/setPassword.spec.js @@ -13,11 +13,11 @@ describe('Client setPassword', () => { expect(error.message).toEqual(`Modifiable password only via recovery or by an administrator`); }); - it('should change the password of the client', async() => { + fit('should change the password of the client', async() => { let error; try { - await models.Client.setPassword(1101, 't0pl3v3l.p455w0rd!'); + await models.Client.setPassword(1105, 't0pl3v3l.p455w0rd!'); } catch (e) { error = e; } From 05a73247a11b416470972e2740a437fa67d62346 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 4 Sep 2023 13:19:01 +0200 Subject: [PATCH 04/10] refs #6159 fix --- modules/client/back/methods/client/specs/setPassword.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/back/methods/client/specs/setPassword.spec.js b/modules/client/back/methods/client/specs/setPassword.spec.js index 6df527e70..841f173bd 100644 --- a/modules/client/back/methods/client/specs/setPassword.spec.js +++ b/modules/client/back/methods/client/specs/setPassword.spec.js @@ -13,7 +13,7 @@ describe('Client setPassword', () => { expect(error.message).toEqual(`Modifiable password only via recovery or by an administrator`); }); - fit('should change the password of the client', async() => { + it('should change the password of the client', async() => { let error; try { From 04d04e6598a37c424400c9855ad55c252e5cf9de Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 6 Sep 2023 13:59:28 +0200 Subject: [PATCH 05/10] refs #6159 fixtrigger --- .../233601/00-updateAfterBusinnesInsert.sql | 42 ------------------- .../233801/00-updateAfterBusinnesInsert.sql | 21 ++++++++++ db/dump/fixtures.sql | 9 ---- .../methods/client/specs/setPassword.spec.js | 2 +- 4 files changed, 22 insertions(+), 52 deletions(-) delete mode 100644 db/changes/233601/00-updateAfterBusinnesInsert.sql create mode 100644 db/changes/233801/00-updateAfterBusinnesInsert.sql diff --git a/db/changes/233601/00-updateAfterBusinnesInsert.sql b/db/changes/233601/00-updateAfterBusinnesInsert.sql deleted file mode 100644 index f2b5dc753..000000000 --- a/db/changes/233601/00-updateAfterBusinnesInsert.sql +++ /dev/null @@ -1,42 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_afterInsert` - AFTER INSERT ON `business` - FOR EACH ROW -BEGIN - CALL worker_updateBusiness(NEW.workerFk); - - IF ( - SELECT NOT active - FROM account.user - WHERE id = NEW.workerFk - ) THEN - UPDATE account.user - SET active = TRUE - WHERE id = NEW.workerFk; - END IF; - - IF ( - SELECT NOT COUNT(aa.id) - FROM account.mailAliasAccount aa - JOIN account.mailAlias ma ON ma.id = aa.mailAlias - WHERE aa.account = NEW.workerFk - AND ma.alias = 'general' - ) THEN - INSERT INTO account.mailAliasAccount (mailAlias, account) - SELECT id, NEW.workerFk - FROM account.mailAlias - WHERE alias = 'general'; - END IF; - - IF ( - SELECT NOT COUNT(account) - FROM account.mailForward - WHERE account = NEW.workerFk - ) THEN - INSERT INTO account.mailForward (account, forwardTo) - SELECT NEW.workerFk, email - FROM account.user - WHERE id = NEW.workerFk; - END IF; -END$$ -DELIMITER ; diff --git a/db/changes/233801/00-updateAfterBusinnesInsert.sql b/db/changes/233801/00-updateAfterBusinnesInsert.sql new file mode 100644 index 000000000..82c71507c --- /dev/null +++ b/db/changes/233801/00-updateAfterBusinnesInsert.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_afterInsert` + AFTER INSERT ON `business` + FOR EACH ROW +BEGIN + CALL worker_updateBusiness(NEW.workerFk); + UPDATE account.user + SET active = TRUE + WHERE id = NEW.workerFk; + + INSERT IGNORE INTO account.mailAliasAccount (mailAlias, account) + SELECT id, NEW.workerFk + FROM account.mailAlias + WHERE alias = 'general'; + + INSERT IGNORE INTO account.mailForward (account, forwardTo) + SELECT NEW.workerFk, email + FROM account.user + WHERE id = NEW.workerFk; +END$$ +DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 5ac355ea4..68922d176 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1965,12 +1965,6 @@ INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) VALUES (1, 'General schedule', 40, 0); -INSERT INTO `account`.`account`(id) - SELECT u.id - FROM account.user u - LEFT JOIN account.account a ON a.id = u.id - WHERE a.id IS NULL; - DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker (PRIMARY KEY (id)) @@ -1994,9 +1988,6 @@ INSERT INTO `vn`.`business` (`id`, `workerFk`, `companyCodeFk`, `started`, `ende DROP TEMPORARY TABLE IF EXISTS tmp.worker; -DELETE FROM `account`.`account` - WHERE id = 1105; - UPDATE `vn`.`business` SET `payedHolidays`= 8 WHERE `id`= 1106; diff --git a/modules/client/back/methods/client/specs/setPassword.spec.js b/modules/client/back/methods/client/specs/setPassword.spec.js index 841f173bd..590172a02 100644 --- a/modules/client/back/methods/client/specs/setPassword.spec.js +++ b/modules/client/back/methods/client/specs/setPassword.spec.js @@ -17,7 +17,7 @@ describe('Client setPassword', () => { let error; try { - await models.Client.setPassword(1105, 't0pl3v3l.p455w0rd!'); + await models.Client.setPassword(1101, 't0pl3v3l.p455w0rd!'); } catch (e) { error = e; } From acd4f398c7d22da5c1f5857cc45ee2cc5fc3dd70 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 21 Sep 2023 08:44:52 +0200 Subject: [PATCH 06/10] refs #6159 procBasedUpdate --- .../233801/00-updateAfterBusinnesInsert.sql | 66 ++++++++++++++----- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/db/changes/233801/00-updateAfterBusinnesInsert.sql b/db/changes/233801/00-updateAfterBusinnesInsert.sql index 82c71507c..71356db80 100644 --- a/db/changes/233801/00-updateAfterBusinnesInsert.sql +++ b/db/changes/233801/00-updateAfterBusinnesInsert.sql @@ -1,21 +1,57 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_afterInsert` - AFTER INSERT ON `business` - FOR EACH ROW +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`account_enable`(vSelf INT) BEGIN - CALL worker_updateBusiness(NEW.workerFk); - UPDATE account.user - SET active = TRUE - WHERE id = NEW.workerFk; +/** + * Enables a worker's account and sets up email configurations. + */ + UPDATE user + SET active = TRUE + WHERE id = vSelf; - INSERT IGNORE INTO account.mailAliasAccount (mailAlias, account) - SELECT id, NEW.workerFk - FROM account.mailAlias - WHERE alias = 'general'; + INSERT IGNORE INTO account + SET id = vSelf; - INSERT IGNORE INTO account.mailForward (account, forwardTo) - SELECT NEW.workerFk, email - FROM account.user - WHERE id = NEW.workerFk; + INSERT IGNORE INTO mailAliasAccount (mailAlias, account) + SELECT id, vSelf + FROM mailAlias + WHERE alias = 'general'; + + INSERT IGNORE INTO mailForward (account, forwardTo) + SELECT vSelf, email + FROM user + WHERE id = vSelf; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBusiness`(vSelf INT) +BEGIN +/** + * Activates an account and configures its email settings. + * + * @param vSelf account id. + */ + DECLARE vOldBusinessFk INT; + DECLARE vNewBusinessFk INT; + + SELECT businessFk INTO vOldBusinessFk FROM worker WHERE id = vSelf; + + SELECT id INTO vNewBusinessFk + FROM business + WHERE workerFk = vSelf + AND util.VN_CURDATE() BETWEEN started AND IFNULL(ended, util.VN_CURDATE()); + + UPDATE worker + SET businessFk = vNewBusinessFk + WHERE id = vSelf; + + IF NOT (vOldBusinessFk <=> vNewBusinessFk) THEN + IF vNewBusinessFk IS NULL THEN + CALL workerDisable(vSelf); + END IF; + IF vOldBusinessFk IS NULL THEN + CALL account.account_enable(vSelf); + END IF; + END IF; END$$ DELIMITER ; From 850df643489f5025453379e822e1ff3ba7e6b0a7 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 21 Sep 2023 14:59:26 +0200 Subject: [PATCH 07/10] refs #6159 moveChangefile --- db/changes/{233801 => 234001}/00-updateAfterBusinnesInsert.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{233801 => 234001}/00-updateAfterBusinnesInsert.sql (100%) diff --git a/db/changes/233801/00-updateAfterBusinnesInsert.sql b/db/changes/234001/00-updateAfterBusinnesInsert.sql similarity index 100% rename from db/changes/233801/00-updateAfterBusinnesInsert.sql rename to db/changes/234001/00-updateAfterBusinnesInsert.sql From 1357b60b9b0ad1992a80f5c8a1108dc06886beaa Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 22 Sep 2023 09:14:08 +0200 Subject: [PATCH 08/10] refs #6159 fixFixtures --- db/dump/fixtures.sql | 3 +++ modules/worker/back/methods/calendar/specs/absences.spec.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 36bb49bc8..fbdd1ad1c 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1967,6 +1967,9 @@ INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) VALUES (1, 'General schedule', 40, 0); +INSERT INTO `vn`.`workerBusinessAgreement` (`id`, `name`, `monthHolidays`, `yearHours`, `started`, `ended`) + VALUES(1, 'flowers', 2.5, 1830, '2001-01-01', NULL); + DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker (PRIMARY KEY (id)) diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index 365773182..ce27c1762 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -50,7 +50,7 @@ describe('Worker absences()', () => { } }); - it('should give the same holidays as worked days since the holidays amount matches the amount of days in a year', async() => { + it('should holidays should equal worked days as both are the same number of days in a year', async() => { const businessId = 1106; const workerId = 1106; From 3013e3cd9cf7c127642eb4529cd1b3f158b4e6fb Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 22 Sep 2023 09:14:59 +0200 Subject: [PATCH 09/10] refs #6159 removeSpaces --- db/dump/fixtures.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index fbdd1ad1c..36400b0d7 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1967,8 +1967,8 @@ INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) VALUES (1, 'General schedule', 40, 0); -INSERT INTO `vn`.`workerBusinessAgreement` (`id`, `name`, `monthHolidays`, `yearHours`, `started`, `ended`) - VALUES(1, 'flowers', 2.5, 1830, '2001-01-01', NULL); +INSERT INTO `vn`.`workerBusinessAgreement` (`id`, `name`, `monthHolidays`, `yearHours`, `started`, `ended`) + VALUES(1, 'flowers', 2.5, 1830, '2001-01-01', NULL); DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker From c175bcfc974b6a8272c1f4aef4ebbd39863d6c1f Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 22 Sep 2023 09:40:37 +0200 Subject: [PATCH 10/10] refs #6159 rename spec --- modules/worker/back/methods/calendar/specs/absences.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index ce27c1762..b27c9549c 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -50,7 +50,7 @@ describe('Worker absences()', () => { } }); - it('should holidays should equal worked days as both are the same number of days in a year', async() => { + it('Should have an equal number of holidays and workdays, as they both total the days in a year', async() => { const businessId = 1106; const workerId = 1106;