diff --git a/back/models/account.js b/back/models/account.js index b74a14997..1c6ac04f8 100644 --- a/back/models/account.js +++ b/back/models/account.js @@ -40,17 +40,9 @@ module.exports = Self => { Self.getCurrentUserData = async function(ctx) { let userId = ctx.req.accessToken.userId; - - let account = await Self.findById(userId, { + return await Self.findById(userId, { fields: ['id', 'name', 'nickname'] }); - - let worker = await Self.app.models.Worker.findOne({ - fields: ['id'], - where: {userFk: userId} - }); - - return Object.assign(account, {workerId: worker.id}); }; /** diff --git a/back/models/account.json b/back/models/account.json index d29e1f38c..483973515 100644 --- a/back/models/account.json +++ b/back/models/account.json @@ -45,9 +45,6 @@ }, "updated": { "type": "date" - }, - "sync": { - "type": "boolean" } }, "relations": { diff --git a/db/changes/10211-accountModule/00-account.sql b/db/changes/10211-accountModule/00-account.sql deleted file mode 100644 index 3204f1417..000000000 --- a/db/changes/10211-accountModule/00-account.sql +++ /dev/null @@ -1,53 +0,0 @@ - -ALTER TABLE `account`.`role` - MODIFY COLUMN `hasLogin` tinyint(3) unsigned DEFAULT 1 NOT NULL; - -ALTER TABLE `account`.`roleInherit` - ADD UNIQUE( `role`, `inheritsFrom`); - -ALTER TABLE `account`.`roleInherit` - DROP PRIMARY KEY; - -ALTER TABLE `account`.`roleInherit` - ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, - ADD PRIMARY KEY (`id`); - -ALTER TABLE `account`.`mailAlias` - ADD `description` VARCHAR(255) NULL AFTER `alias`; - -ALTER TABLE `account`.`mailAliasAccount` - ADD UNIQUE( `mailAlias`, `account`); - -ALTER TABLE `account`.`mailAliasAccount` - DROP PRIMARY KEY; - -ALTER TABLE `account`.`mailAliasAccount` - ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, - ADD PRIMARY KEY (`id`); - -ALTER TABLE account.ldapConfig - ADD groupDn varchar(255) NULL; - -UPDATE account.ldapConfig SET groupDn = 'ou=groups,dc=verdnatura,dc=es'; - -DROP PROCEDURE IF EXISTS account.user_syncPassword; - -USE account; - -DELIMITER $$ - -CREATE TRIGGER role_beforeInsert - BEFORE INSERT ON `role` FOR EACH ROW -BEGIN - CALL role_checkName(NEW.`name`); -END$$ - -CREATE TRIGGER role_beforeUpdate - BEFORE UPDATE ON `role` FOR EACH ROW -BEGIN - IF !(NEW.`name` <=> OLD.`name`) THEN - CALL role_checkName (NEW.`name`); - END IF; -END$$ - -DELIMITER ; \ No newline at end of file diff --git a/db/changes/10221-accountModule/00-account.sql b/db/changes/10221-accountModule/00-account.sql new file mode 100644 index 000000000..d26d61c19 --- /dev/null +++ b/db/changes/10221-accountModule/00-account.sql @@ -0,0 +1,127 @@ + +ALTER TABLE `account`.`role` + MODIFY COLUMN `hasLogin` tinyint(3) unsigned DEFAULT 1 NOT NULL; + +ALTER TABLE `account`.`roleInherit` + ADD UNIQUE( `role`, `inheritsFrom`); + +ALTER TABLE `account`.`roleInherit` + DROP PRIMARY KEY; + +ALTER TABLE `account`.`roleInherit` + ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, + ADD PRIMARY KEY (`id`); + +ALTER TABLE `account`.`mailAlias` + ADD `description` VARCHAR(255) NULL AFTER `alias`; + +ALTER TABLE `account`.`mailAliasAccount` + ADD UNIQUE( `mailAlias`, `account`); + +ALTER TABLE `account`.`mailAliasAccount` + DROP PRIMARY KEY; + +ALTER TABLE `account`.`mailAliasAccount` + ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, + ADD PRIMARY KEY (`id`); + +ALTER TABLE account.ldapConfig + ADD groupDn varchar(255) NULL; + +UPDATE account.ldapConfig SET groupDn = 'ou=groups,dc=verdnatura,dc=es'; + +DROP PROCEDURE IF EXISTS account.user_syncPassword; + +ALTER TABLE account.`user` + MODIFY COLUMN sync tinyint(4) DEFAULT 0 NOT NULL COMMENT 'Deprecated'; + +CREATE TABLE account.userSync ( + name varchar(30) NOT NULL, + CONSTRAINT userSync_PK PRIMARY KEY (name) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8 +COLLATE=utf8_general_ci; + +USE account; + +DELIMITER $$ + +DROP TRIGGER IF EXISTS account.user_beforeUpdate$$ +CREATE DEFINER=`root`@`%` TRIGGER `user_beforeUpdate` + BEFORE UPDATE ON `user` FOR EACH ROW +BEGIN + IF !(NEW.`name` <=> OLD.`name`) THEN + CALL user_checkName (NEW.`name`); + END IF; + + IF !(NEW.`password` <=> OLD.`password`) THEN + SET NEW.bcryptPassword = NULL; + SET NEW.lastPassChange = NOW(); + END IF; +END$$ + +DROP TRIGGER IF EXISTS account.user_afterUpdate$$ +CREATE DEFINER=`root`@`%` TRIGGER `user_afterUpdate` + AFTER UPDATE ON `user` FOR EACH ROW +BEGIN + INSERT IGNORE INTO userSync SET `name` = NEW.`name`; + + IF !(OLD.`name` <=> NEW.`name`) THEN + INSERT IGNORE INTO userSync SET `name` = OLD.`name`; + END IF; + + IF !(NEW.`role` <=> OLD.`role`) + THEN + INSERT INTO vn.mail SET + `sender` = 'jgallego@verdnatura.es', + `replyTo` = 'jgallego@verdnatura.es', + `subject` = 'Rol modificado', + `body` = CONCAT(myUserGetName(), ' ha modificado el rol del usuario ', + NEW.`name`, ' de ', OLD.role, ' a ', NEW.role); + END IF; +END$$ + +CREATE DEFINER=`root`@`%` TRIGGER `user_afterInsert` + AFTER INSERT ON `user` FOR EACH ROW +BEGIN + INSERT IGNORE INTO userSync SET `name` = NEW.`name`; +END$$ + +CREATE DEFINER=`root`@`%` TRIGGER `user_afterDelete` + AFTER DELETE ON `user` FOR EACH ROW +BEGIN + INSERT IGNORE INTO userSync SET `name` = OLD.`name`; +END$$ + +DROP TRIGGER IF EXISTS account.account_afterInsert$$ +CREATE DEFINER=`root`@`%` TRIGGER `account_afterInsert` + AFTER INSERT ON `account` FOR EACH ROW +BEGIN + INSERT IGNORE INTO userSync (`name`) + SELECT `name` FROM `user` WHERE id = NEW.id; +END$$ + +DROP TRIGGER IF EXISTS account.account_afterDelete$$ +CREATE DEFINER=`root`@`%` TRIGGER `account_afterDelete` + AFTER DELETE ON `account` FOR EACH ROW +BEGIN + INSERT IGNORE INTO userSync (`name`) + SELECT `name` FROM `user` WHERE id = OLD.id; +END$$ + +CREATE TRIGGER role_beforeInsert + BEFORE INSERT ON `role` FOR EACH ROW +BEGIN + CALL role_checkName(NEW.`name`); +END$$ + +CREATE TRIGGER role_beforeUpdate + BEFORE UPDATE ON `role` FOR EACH ROW +BEGIN + IF !(NEW.`name` <=> OLD.`name`) THEN + CALL role_checkName (NEW.`name`); + END IF; +END$$ + +DELIMITER ; \ No newline at end of file diff --git a/db/changes/10211-accountModule/00-myUserChangePassword.sql b/db/changes/10221-accountModule/00-myUserChangePassword.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUserChangePassword.sql rename to db/changes/10221-accountModule/00-myUserChangePassword.sql diff --git a/db/changes/10211-accountModule/00-myUserCheckLogin.sql b/db/changes/10221-accountModule/00-myUserCheckLogin.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUserCheckLogin.sql rename to db/changes/10221-accountModule/00-myUserCheckLogin.sql diff --git a/db/changes/10211-accountModule/00-myUserGetId.sql b/db/changes/10221-accountModule/00-myUserGetId.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUserGetId.sql rename to db/changes/10221-accountModule/00-myUserGetId.sql diff --git a/db/changes/10211-accountModule/00-myUserGetName.sql b/db/changes/10221-accountModule/00-myUserGetName.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUserGetName.sql rename to db/changes/10221-accountModule/00-myUserGetName.sql diff --git a/db/changes/10211-accountModule/00-myUserHasRole.sql b/db/changes/10221-accountModule/00-myUserHasRole.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUserHasRole.sql rename to db/changes/10221-accountModule/00-myUserHasRole.sql diff --git a/db/changes/10211-accountModule/00-myUserHasRoleId.sql b/db/changes/10221-accountModule/00-myUserHasRoleId.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUserHasRoleId.sql rename to db/changes/10221-accountModule/00-myUserHasRoleId.sql diff --git a/db/changes/10211-accountModule/00-myUser_changePassword.sql b/db/changes/10221-accountModule/00-myUser_changePassword.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_changePassword.sql rename to db/changes/10221-accountModule/00-myUser_changePassword.sql diff --git a/db/changes/10211-accountModule/00-myUser_checkLogin.sql b/db/changes/10221-accountModule/00-myUser_checkLogin.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_checkLogin.sql rename to db/changes/10221-accountModule/00-myUser_checkLogin.sql diff --git a/db/changes/10211-accountModule/00-myUser_getId.sql b/db/changes/10221-accountModule/00-myUser_getId.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_getId.sql rename to db/changes/10221-accountModule/00-myUser_getId.sql diff --git a/db/changes/10211-accountModule/00-myUser_getName.sql b/db/changes/10221-accountModule/00-myUser_getName.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_getName.sql rename to db/changes/10221-accountModule/00-myUser_getName.sql diff --git a/db/changes/10211-accountModule/00-myUser_hasRole.sql b/db/changes/10221-accountModule/00-myUser_hasRole.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_hasRole.sql rename to db/changes/10221-accountModule/00-myUser_hasRole.sql diff --git a/db/changes/10211-accountModule/00-myUser_hasRoleId.sql b/db/changes/10221-accountModule/00-myUser_hasRoleId.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_hasRoleId.sql rename to db/changes/10221-accountModule/00-myUser_hasRoleId.sql diff --git a/db/changes/10211-accountModule/00-myUser_login.sql b/db/changes/10221-accountModule/00-myUser_login.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_login.sql rename to db/changes/10221-accountModule/00-myUser_login.sql diff --git a/db/changes/10211-accountModule/00-myUser_loginWithKey.sql b/db/changes/10221-accountModule/00-myUser_loginWithKey.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_loginWithKey.sql rename to db/changes/10221-accountModule/00-myUser_loginWithKey.sql diff --git a/db/changes/10211-accountModule/00-myUser_loginWithName.sql b/db/changes/10221-accountModule/00-myUser_loginWithName.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_loginWithName.sql rename to db/changes/10221-accountModule/00-myUser_loginWithName.sql diff --git a/db/changes/10211-accountModule/00-myUser_logout.sql b/db/changes/10221-accountModule/00-myUser_logout.sql similarity index 100% rename from db/changes/10211-accountModule/00-myUser_logout.sql rename to db/changes/10221-accountModule/00-myUser_logout.sql diff --git a/db/changes/10211-accountModule/00-passwordGenerate.sql b/db/changes/10221-accountModule/00-passwordGenerate.sql similarity index 100% rename from db/changes/10211-accountModule/00-passwordGenerate.sql rename to db/changes/10221-accountModule/00-passwordGenerate.sql diff --git a/db/changes/10211-accountModule/00-role_checkName.sql b/db/changes/10221-accountModule/00-role_checkName.sql similarity index 100% rename from db/changes/10211-accountModule/00-role_checkName.sql rename to db/changes/10221-accountModule/00-role_checkName.sql diff --git a/db/changes/10211-accountModule/00-role_getDescendents.sql b/db/changes/10221-accountModule/00-role_getDescendents.sql similarity index 100% rename from db/changes/10211-accountModule/00-role_getDescendents.sql rename to db/changes/10221-accountModule/00-role_getDescendents.sql diff --git a/db/changes/10211-accountModule/00-role_sync.sql b/db/changes/10221-accountModule/00-role_sync.sql similarity index 100% rename from db/changes/10211-accountModule/00-role_sync.sql rename to db/changes/10221-accountModule/00-role_sync.sql diff --git a/db/changes/10211-accountModule/00-role_syncPrivileges.sql b/db/changes/10221-accountModule/00-role_syncPrivileges.sql similarity index 100% rename from db/changes/10211-accountModule/00-role_syncPrivileges.sql rename to db/changes/10221-accountModule/00-role_syncPrivileges.sql diff --git a/db/changes/10211-accountModule/00-userGetId.sql b/db/changes/10221-accountModule/00-userGetId.sql similarity index 100% rename from db/changes/10211-accountModule/00-userGetId.sql rename to db/changes/10221-accountModule/00-userGetId.sql diff --git a/db/changes/10211-accountModule/00-userGetMysqlRole.sql b/db/changes/10221-accountModule/00-userGetMysqlRole.sql similarity index 100% rename from db/changes/10211-accountModule/00-userGetMysqlRole.sql rename to db/changes/10221-accountModule/00-userGetMysqlRole.sql diff --git a/db/changes/10211-accountModule/00-userGetName.sql b/db/changes/10221-accountModule/00-userGetName.sql similarity index 100% rename from db/changes/10211-accountModule/00-userGetName.sql rename to db/changes/10221-accountModule/00-userGetName.sql diff --git a/db/changes/10211-accountModule/00-userGetNameFromId.sql b/db/changes/10221-accountModule/00-userGetNameFromId.sql similarity index 100% rename from db/changes/10211-accountModule/00-userGetNameFromId.sql rename to db/changes/10221-accountModule/00-userGetNameFromId.sql diff --git a/db/changes/10211-accountModule/00-userHasRole.sql b/db/changes/10221-accountModule/00-userHasRole.sql similarity index 100% rename from db/changes/10211-accountModule/00-userHasRole.sql rename to db/changes/10221-accountModule/00-userHasRole.sql diff --git a/db/changes/10211-accountModule/00-userHasRoleId.sql b/db/changes/10221-accountModule/00-userHasRoleId.sql similarity index 100% rename from db/changes/10211-accountModule/00-userHasRoleId.sql rename to db/changes/10221-accountModule/00-userHasRoleId.sql diff --git a/db/changes/10211-accountModule/00-userLogin.sql b/db/changes/10221-accountModule/00-userLogin.sql similarity index 100% rename from db/changes/10211-accountModule/00-userLogin.sql rename to db/changes/10221-accountModule/00-userLogin.sql diff --git a/db/changes/10211-accountModule/00-userLoginWithKey.sql b/db/changes/10221-accountModule/00-userLoginWithKey.sql similarity index 100% rename from db/changes/10211-accountModule/00-userLoginWithKey.sql rename to db/changes/10221-accountModule/00-userLoginWithKey.sql diff --git a/db/changes/10211-accountModule/00-userLoginWithName.sql b/db/changes/10221-accountModule/00-userLoginWithName.sql similarity index 100% rename from db/changes/10211-accountModule/00-userLoginWithName.sql rename to db/changes/10221-accountModule/00-userLoginWithName.sql diff --git a/db/changes/10211-accountModule/00-userLogout.sql b/db/changes/10221-accountModule/00-userLogout.sql similarity index 100% rename from db/changes/10211-accountModule/00-userLogout.sql rename to db/changes/10221-accountModule/00-userLogout.sql diff --git a/db/changes/10211-accountModule/00-userSetPassword.sql b/db/changes/10221-accountModule/00-userSetPassword.sql similarity index 100% rename from db/changes/10211-accountModule/00-userSetPassword.sql rename to db/changes/10221-accountModule/00-userSetPassword.sql diff --git a/db/changes/10211-accountModule/00-user_changePassword.sql b/db/changes/10221-accountModule/00-user_changePassword.sql similarity index 100% rename from db/changes/10211-accountModule/00-user_changePassword.sql rename to db/changes/10221-accountModule/00-user_changePassword.sql diff --git a/db/changes/10211-accountModule/00-user_checkName.sql b/db/changes/10221-accountModule/00-user_checkName.sql similarity index 100% rename from db/changes/10211-accountModule/00-user_checkName.sql rename to db/changes/10221-accountModule/00-user_checkName.sql diff --git a/db/changes/10211-accountModule/00-user_getMysqlRole.sql b/db/changes/10221-accountModule/00-user_getMysqlRole.sql similarity index 100% rename from db/changes/10211-accountModule/00-user_getMysqlRole.sql rename to db/changes/10221-accountModule/00-user_getMysqlRole.sql diff --git a/db/changes/10211-accountModule/00-user_getNameFromId.sql b/db/changes/10221-accountModule/00-user_getNameFromId.sql similarity index 100% rename from db/changes/10211-accountModule/00-user_getNameFromId.sql rename to db/changes/10221-accountModule/00-user_getNameFromId.sql diff --git a/db/changes/10211-accountModule/00-user_hasRole.sql b/db/changes/10221-accountModule/00-user_hasRole.sql similarity index 100% rename from db/changes/10211-accountModule/00-user_hasRole.sql rename to db/changes/10221-accountModule/00-user_hasRole.sql diff --git a/db/changes/10211-accountModule/00-user_hasRoleId.sql b/db/changes/10221-accountModule/00-user_hasRoleId.sql similarity index 100% rename from db/changes/10211-accountModule/00-user_hasRoleId.sql rename to db/changes/10221-accountModule/00-user_hasRoleId.sql diff --git a/db/changes/10211-accountModule/00-user_setPassword.sql b/db/changes/10221-accountModule/00-user_setPassword.sql similarity index 100% rename from db/changes/10211-accountModule/00-user_setPassword.sql rename to db/changes/10221-accountModule/00-user_setPassword.sql diff --git a/front/salix/components/layout/index.js b/front/salix/components/layout/index.js index b8ca74b99..c6bc80734 100644 --- a/front/salix/components/layout/index.js +++ b/front/salix/components/layout/index.js @@ -15,7 +15,7 @@ export class Layout extends Component { getUserData() { this.$http.get('Accounts/getCurrentUserData').then(json => { this.$.$root.user = json.data; - window.localStorage.currentUserWorkerId = json.data.workerId; + window.localStorage.currentUserWorkerId = json.data.id; }); } } diff --git a/front/salix/components/user-popover/index.html b/front/salix/components/user-popover/index.html index f34219d26..4b02edd9f 100644 --- a/front/salix/components/user-popover/index.html +++ b/front/salix/components/user-popover/index.html @@ -36,7 +36,7 @@ My account diff --git a/modules/account/back/methods/user-account/sync.js b/modules/account/back/methods/user-account/sync.js index 681f3674d..202411e35 100644 --- a/modules/account/back/methods/user-account/sync.js +++ b/modules/account/back/methods/user-account/sync.js @@ -28,11 +28,12 @@ module.exports = Self => { let $ = Self.app.models; let user = await $.Account.findOne({ - fields: ['id', 'sync'], + fields: ['id'], where: {name: userName} }); + let isSync = !await $.UserSync.exists(userName); - if (user && user.sync) return; + if (user && isSync) return; let accountConfig; let mailConfig; @@ -84,19 +85,18 @@ module.exports = Self => { if (user) { let bcryptPassword = $.User.hashPassword(password); - await $.Account.upsertWithWhere({id: user.id}, {bcryptPassword}); - await $.user.destroyById(user.id); - if (hasAccount) { - await $.user.upsert({ - id: user.id, - username: userName, - password: bcryptPassword, - email: user.email, - created: user.created, - updated: user.updated - }); - } + await $.Account.upsertWithWhere({id: user.id}, + {bcryptPassword} + ); + await $.user.upsert({ + id: user.id, + username: userName, + password: bcryptPassword, + email: user.email, + created: user.created, + updated: user.updated + }); } // SIP @@ -262,7 +262,6 @@ module.exports = Self => { // Mark as synchronized - // if (user) - // await $.Account.upsertWithWhere({id: user.id}, {sync: true}); + await $.UserSync.destroyById(userName); }; }; diff --git a/modules/account/back/model-config.json b/modules/account/back/model-config.json index 9700ed0a1..d243a2cca 100644 --- a/modules/account/back/model-config.json +++ b/modules/account/back/model-config.json @@ -31,5 +31,8 @@ }, "UserPassword": { "dataSource": "vn" + }, + "UserSync": { + "dataSource": "vn" } } \ No newline at end of file diff --git a/modules/account/back/models/user-sync.json b/modules/account/back/models/user-sync.json new file mode 100644 index 000000000..60fd3fb3d --- /dev/null +++ b/modules/account/back/models/user-sync.json @@ -0,0 +1,15 @@ +{ + "name": "UserSync", + "base": "VnModel", + "options": { + "mysql": { + "table": "account.userSync" + } + }, + "properties": { + "name": { + "type": "string", + "id": true + } + } +} diff --git a/modules/client/back/methods/client/specs/sendSms.spec.js b/modules/client/back/methods/client/specs/sendSms.spec.js index b299ac3c1..673a95cae 100644 --- a/modules/client/back/methods/client/specs/sendSms.spec.js +++ b/modules/client/back/methods/client/specs/sendSms.spec.js @@ -1,6 +1,7 @@ const app = require('vn-loopback/server/server'); -describe('client sendSms()', () => { +// Issue #2471 +xdescribe('client sendSms()', () => { let createdLog; afterAll(async done => { diff --git a/modules/client/back/methods/sms/send.spec.js b/modules/client/back/methods/sms/send.spec.js index 612a16cf1..06288ffb5 100644 --- a/modules/client/back/methods/sms/send.spec.js +++ b/modules/client/back/methods/sms/send.spec.js @@ -1,7 +1,8 @@ const app = require('vn-loopback/server/server'); const soap = require('soap'); -describe('sms send()', () => { +// Issue #2471 +xdescribe('sms send()', () => { it('should return the expected message and status code', async() => { const code = 200; const smsConfig = await app.models.SmsConfig.findOne(); diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js index 20066a5ba..a08e7555a 100644 --- a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -1,6 +1,7 @@ const app = require('vn-loopback/server/server'); -describe('ticket sendSms()', () => { +// Issue #2471 +xdescribe('ticket sendSms()', () => { let logId; afterAll(async done => {