3609-ticket_basic-data #875
|
@ -1,7 +1,13 @@
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.getSynchronizer = async function() {
|
Self.getSynchronizer = async function() {
|
||||||
return await Self.findOne({fields: ['id']});
|
let NODE_ENV = process.env.NODE_ENV;
|
||||||
|
if (!NODE_ENV || NODE_ENV == 'development')
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return await Self.findOne({
|
||||||
|
fields: ['id', 'rolePrefix', 'userPrefix', 'userHost']
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(Self.prototype, {
|
Object.assign(Self.prototype, {
|
||||||
|
@ -14,17 +20,16 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
|
|
||||||
async syncUser(userName, info, password) {
|
async syncUser(userName, info, password) {
|
||||||
const mysqlHost = '%';
|
|
||||||
|
|
||||||
let mysqlUser = userName;
|
let mysqlUser = userName;
|
||||||
if (this.dbType == 'MySQL') mysqlUser = `!${mysqlUser}`;
|
if (this.dbType == 'MySQL')
|
||||||
|
mysqlUser = this.userPrefix + mysqlUser;
|
||||||
|
|
||||||
const [row] = await Self.rawSql(
|
const [row] = await Self.rawSql(
|
||||||
`SELECT COUNT(*) AS nRows
|
`SELECT COUNT(*) AS nRows
|
||||||
FROM mysql.user
|
FROM mysql.user
|
||||||
WHERE User = ?
|
WHERE User = ?
|
||||||
AND Host = ?`,
|
AND Host = ?`,
|
||||||
[mysqlUser, mysqlHost]
|
[mysqlUser, this.userHost]
|
||||||
);
|
);
|
||||||
let userExists = row.nRows > 0;
|
let userExists = row.nRows > 0;
|
||||||
|
|
||||||
|
@ -35,11 +40,10 @@ module.exports = Self => {
|
||||||
FROM mysql.global_priv
|
FROM mysql.global_priv
|
||||||
WHERE User = ?
|
WHERE User = ?
|
||||||
AND Host = ?`,
|
AND Host = ?`,
|
||||||
[mysqlUser, mysqlHost]
|
[mysqlUser, this.userHost]
|
||||||
);
|
);
|
||||||
const priv = row && JSON.parse(row.priv);
|
const priv = row && JSON.parse(row.priv);
|
||||||
const role = priv && priv.default_role;
|
isUpdatable = !row || (priv && priv.autogenerated);
|
||||||
isUpdatable = !row || (role && role.startsWith('z-'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isUpdatable) {
|
if (!isUpdatable) {
|
||||||
|
@ -51,31 +55,27 @@ module.exports = Self => {
|
||||||
if (password) {
|
if (password) {
|
||||||
if (!userExists) {
|
if (!userExists) {
|
||||||
await Self.rawSql('CREATE USER ?@? IDENTIFIED BY ?',
|
await Self.rawSql('CREATE USER ?@? IDENTIFIED BY ?',
|
||||||
[mysqlUser, mysqlHost, password]
|
[mysqlUser, this.userHost, password]);
|
||||||
);
|
|
||||||
userExists = true;
|
userExists = true;
|
||||||
} else {
|
} else {
|
||||||
switch (this.dbType) {
|
switch (this.dbType) {
|
||||||
case 'MariaDB':
|
case 'MariaDB':
|
||||||
await Self.rawSql('ALTER USER ?@? IDENTIFIED BY ?',
|
await Self.rawSql('ALTER USER ?@? IDENTIFIED BY ?',
|
||||||
[mysqlUser, mysqlHost, password]
|
[mysqlUser, this.userHost, password]);
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
await Self.rawSql('SET PASSWORD FOR ?@? = PASSWORD(?)',
|
await Self.rawSql('SET PASSWORD FOR ?@? = PASSWORD(?)',
|
||||||
[mysqlUser, mysqlHost, password]
|
[mysqlUser, this.userHost, password]);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userExists && this.dbType == 'MariaDB') {
|
if (userExists && this.dbType == 'MariaDB') {
|
||||||
let role = `z-${info.user.role().name}`;
|
let role = `${this.rolePrefix}${info.user.role().name}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Self.rawSql('REVOKE ALL, GRANT OPTION FROM ?@?',
|
await Self.rawSql('REVOKE ALL, GRANT OPTION FROM ?@?',
|
||||||
[mysqlUser, mysqlHost]
|
[mysqlUser, this.userHost]);
|
||||||
);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code == 'ER_REVOKE_GRANTS')
|
if (err.code == 'ER_REVOKE_GRANTS')
|
||||||
console.warn(`${err.code}: ${err.sqlMessage}: ${err.sql}`);
|
console.warn(`${err.code}: ${err.sqlMessage}: ${err.sql}`);
|
||||||
|
@ -83,21 +83,18 @@ module.exports = Self => {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
await Self.rawSql('GRANT ? TO ?@?',
|
await Self.rawSql('GRANT ? TO ?@?',
|
||||||
[role, mysqlUser, mysqlHost]
|
[role, mysqlUser, this.userHost]);
|
||||||
);
|
|
||||||
|
|
||||||
if (role) {
|
if (role) {
|
||||||
await Self.rawSql('SET DEFAULT ROLE ? FOR ?@?',
|
await Self.rawSql('SET DEFAULT ROLE ? FOR ?@?',
|
||||||
[role, mysqlUser, mysqlHost]
|
[role, mysqlUser, this.userHost]);
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
await Self.rawSql('SET DEFAULT ROLE NONE FOR ?@?',
|
await Self.rawSql('SET DEFAULT ROLE NONE FOR ?@?',
|
||||||
[mysqlUser, mysqlHost]
|
[mysqlUser, this.userHost]);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (userExists)
|
} else if (userExists)
|
||||||
await Self.rawSql('DROP USER ?@?', [mysqlUser, mysqlHost]);
|
await Self.rawSql('DROP USER ?@?', [mysqlUser, this.userHost]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,18 @@
|
||||||
},
|
},
|
||||||
"mysqlPassword": {
|
"mysqlPassword": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"rolePrefix": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"userPrefix": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"userHost": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"tplUser": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
url="Workers/activeWithRole"
|
url="Workers/activeWithRole"
|
||||||
search-function="{firstName: $search}"
|
search-function="{firstName: $search}"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
where="{role: {inq: ['salesPerson', 'officeBoss']}}"
|
where="{role: {inq: ['salesBoss', 'salesPerson', 'officeBoss']}}"
|
||||||
label="Salesperson">
|
label="Salesperson">
|
||||||
<tpl-item>{{firstName}} {{name}}</tpl-item>
|
<tpl-item>{{firstName}} {{name}}</tpl-item>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
url="Workers/activeWithRole"
|
url="Workers/activeWithRole"
|
||||||
search-function="{firstName: $search}"
|
search-function="{firstName: $search}"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
where="{role: 'salesPerson'}"
|
where="{role: {inq: ['salesBoss', 'salesPerson']}}"
|
||||||
label="Attended by">
|
label="Attended by">
|
||||||
<tpl-item>{{firstName}} {{name}}</tpl-item>
|
<tpl-item>{{firstName}} {{name}}</tpl-item>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
|
|
|
@ -12,8 +12,6 @@ module.exports = {
|
||||||
const failedtickets = [];
|
const failedtickets = [];
|
||||||
for (const ticket of tickets) {
|
for (const ticket of tickets) {
|
||||||
try {
|
try {
|
||||||
await db.rawSql('START TRANSACTION');
|
|
||||||
|
|
||||||
await db.rawSql(`CALL vn.ticket_closeByTicket(?)`, [ticket.id]);
|
await db.rawSql(`CALL vn.ticket_closeByTicket(?)`, [ticket.id]);
|
||||||
|
|
||||||
const invoiceOut = await db.findOne(`
|
const invoiceOut = await db.findOne(`
|
||||||
|
@ -91,9 +89,7 @@ module.exports = {
|
||||||
const email = new Email('delivery-note-link', args);
|
const email = new Email('delivery-note-link', args);
|
||||||
await email.send();
|
await email.send();
|
||||||
}
|
}
|
||||||
await db.rawSql('COMMIT');
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await db.rawSql('ROLLBACK');
|
|
||||||
// Domain not found
|
// Domain not found
|
||||||
if (error.responseCode == 450)
|
if (error.responseCode == 450)
|
||||||
return invalidEmail(ticket);
|
return invalidEmail(ticket);
|
||||||
|
|
|
@ -5,7 +5,7 @@ h2 {
|
||||||
|
|
||||||
.table-title {
|
.table-title {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
font-size: 0.8rem
|
font-size: .8rem
|
||||||
}
|
}
|
||||||
|
|
||||||
.table-title h2 {
|
.table-title h2 {
|
||||||
|
@ -16,9 +16,12 @@ h2 {
|
||||||
font-size: 22px
|
font-size: 22px
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#nickname h2 {
|
#nickname h2 {
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
word-wrap: break-word
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
#phytosanitary {
|
#phytosanitary {
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
<!-- End of rectified invoices block -->
|
<!-- End of rectified invoices block -->
|
||||||
|
|
||||||
<!-- Sales block -->
|
<!-- Sales block -->
|
||||||
<div class="vn-mt-lg no-page-break" v-for="ticket in tickets">
|
<div class="vn-mt-lg" v-for="ticket in tickets">
|
||||||
<div class="table-title clearfix">
|
<div class="table-title clearfix">
|
||||||
<div class="pull-left">
|
<div class="pull-left">
|
||||||
<h2>{{$t('deliveryNote')}}</strong>
|
<h2>{{$t('deliveryNote')}}</strong>
|
||||||
|
|
Loading…
Reference in New Issue