From 71eb44d0833b1d37b8c72e51f23cc9ec2a35c0b0 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 9 Sep 2024 09:58:20 +0200 Subject: [PATCH 1/4] 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 829ecba2ef57050e54369a4bce6e4c123c3a15a1 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 Sep 2024 08:30:05 +0200 Subject: [PATCH 2/4] 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 3/4] 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 4/4] 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' } ],