2177-accountModule #373
|
@ -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});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,9 +45,6 @@
|
|||
},
|
||||
"updated": {
|
||||
"type": "date"
|
||||
},
|
||||
"sync": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
|
@ -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 ;
|
|
@ -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 ;
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
</vn-icon-button>
|
||||
</div>
|
||||
<a
|
||||
ui-sref="worker.card.summary({id: $root.user.workerId})"
|
||||
ui-sref="worker.card.summary({id: $root.user.id})"
|
||||
class="vn-button colored"
|
||||
translate>
|
||||
My account
|
||||
|
|
|
@ -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,10 +85,10 @@ 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 $.Account.upsertWithWhere({id: user.id},
|
||||
{bcryptPassword}
|
||||
);
|
||||
await $.user.upsert({
|
||||
id: user.id,
|
||||
username: userName,
|
||||
|
@ -97,7 +98,6 @@ module.exports = Self => {
|
|||
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);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -31,5 +31,8 @@
|
|||
},
|
||||
"UserPassword": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"UserSync": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "UserSync",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "account.userSync"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"id": true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('client sendSms()', () => {
|
||||
// Issue #2471
|
||||
xdescribe('client sendSms()', () => {
|
||||
let createdLog;
|
||||
|
||||
afterAll(async done => {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket sendSms()', () => {
|
||||
// Issue #2471
|
||||
xdescribe('ticket sendSms()', () => {
|
||||
let logId;
|
||||
|
||||
afterAll(async done => {
|
||||
|
|
Loading…
Reference in New Issue