diff --git a/modules/claim/back/models/claim-state.json b/modules/claim/back/models/claim-state.json index c905aacba..0d9e3c87f 100644 --- a/modules/claim/back/models/claim-state.json +++ b/modules/claim/back/models/claim-state.json @@ -21,7 +21,7 @@ "required": true }, "priority": { - "type": "nomber", + "type": "number", "required": true } }, diff --git a/print/core/component.js b/print/core/component.js index 836b8c9d9..1b88ac292 100644 --- a/print/core/component.js +++ b/print/core/component.js @@ -87,17 +87,31 @@ class Component { return component; } - async render() { + component() { + if (this._component) + return this._component; + const component = this.build(); const i18n = new VueI18n(config.i18n); - const app = new Vue({ + this._component = new Vue({ i18n: i18n, render: h => h(component, { props: this.args }) }); - return renderer.renderToString(app); + return this._component; + } + + /** + * @return {Promise} Rendered component + */ + async render() { + const c = this.component(); + console.log(c); + return renderer.renderToString( + this.component() + ); } } diff --git a/print/core/components/attachment/attachment.js b/print/core/components/attachment/attachment.js index 2d4e74cdc..1975320cf 100755 --- a/print/core/components/attachment/attachment.js +++ b/print/core/components/attachment/attachment.js @@ -15,6 +15,7 @@ module.exports = { const props = this.args; let query = ''; for (let param in props) { + if (param instanceof Object) return; if (query != '') query += '&'; query += `${param}=${props[param]}`; diff --git a/print/core/email.js b/print/core/email.js index faf744e77..27a457a92 100644 --- a/print/core/email.js +++ b/print/core/email.js @@ -2,7 +2,7 @@ const path = require('path'); const smtp = require('./smtp'); const Component = require('./component'); const Report = require('./report'); -const db = require('./database'); +// const db = require('./database'); const config = require('./config'); if (!process.env.OPENSSL_CONF) @@ -20,9 +20,9 @@ class Email extends Component { } async getSubject() { - if (!this.lang) await this.getLang(); + const lang = this.args.auth.lang; const locale = this.locale.messages; - const userLocale = locale[this.lang]; + const userLocale = locale[lang]; if (!userLocale) { const fallbackLocale = config.i18n.fallbackLocale; @@ -33,18 +33,19 @@ class Email extends Component { return userLocale.subject; } - async getLang() { + /* async getLang() { const clientId = this.args.clientId; const lang = await db.findOne(` - SELECT lang FROM account.user + SELECT lang FROM account.user WHERE id = ?`, [clientId]).then(rows => { return rows.lang; }); this.lang = lang; - } + } */ async send() { const instance = this.build(); + const component = this.component(); const rendered = await this.render(); const attachments = []; const getAttachments = async(componentPath, files) => { @@ -77,9 +78,12 @@ class Email extends Component { if (this.attachments) await getAttachments(this.path, this.attachments); + console.log(await component.getLang(101)); + const localeSubject = await this.getSubject(); const options = { to: this.args.recipient, + replyTo: this.args.auth.email, subject: localeSubject, html: rendered, attachments: attachments diff --git a/print/core/mixins/prop-validator.js b/print/core/mixins/prop-validator.js index a73197ebf..16c71a6db 100644 --- a/print/core/mixins/prop-validator.js +++ b/print/core/mixins/prop-validator.js @@ -19,8 +19,7 @@ const validator = { throw new Error(`Required properties not found [${required}]`); } }, - props: ['isPreview'] + props: ['isPreview', 'authorization'] }; - Vue.mixin(validator); diff --git a/print/core/mixins/user-locale.js b/print/core/mixins/user-locale.js index 2b9b0c8c5..7d5b0cea7 100644 --- a/print/core/mixins/user-locale.js +++ b/print/core/mixins/user-locale.js @@ -4,15 +4,16 @@ const config = require('../config'); const fallbackLocale = config.i18n.fallbackLocale; const userLocale = { async serverPrefetch() { - console.log(this.auth); - if (this.clientId) - this.locale = await this.getLocale(this.clientId); + /* if (this.clientId) + this.locale = await this.getLocale(this.clientId); */ - if (this.locale) - this.$i18n.locale = this.locale; + if (this.clientLang) { + if (this.auth) + this.$i18n.locale = this.auth.lang; + } }, methods: { - getLocale(clientId) { + getLang(clientId) { return db.findOne(` SELECT IF(u.lang IS NOT NULL, u.lang, LOWER(ct.code)) lang FROM client c @@ -23,6 +24,10 @@ const userLocale = { return rows.lang; else return fallbackLocale; }); + }, + + setLocale() { + this.$i18n.locale = this.auth.lang; } }, props: ['auth', 'clientId'] diff --git a/print/core/router.js b/print/core/router.js index 00a9821c1..efb5d9520 100644 --- a/print/core/router.js +++ b/print/core/router.js @@ -17,20 +17,30 @@ module.exports = app => { for (let method of methods) paths.push(`/api/${method}/*`); - app.use(paths, async function(request, response, next) { - const authorization = getToken(request); - const query = `SELECT userId, ttl, created - FROM salix.AccessToken WHERE id = ?`; + app.use(paths, async function(req, res, next) { + const token = getToken(req); + const query = `SELECT at.id, at.userId, eu.email, u.lang, at.ttl, at.created + FROM salix.AccessToken at + JOIN account.user u ON u.id = at.userid + JOIN account.emailUser eu ON eu.userFk = u.id + WHERE at.id = ?`; try { - const authToken = await db.findOne(query, [authorization]); + const auth = await db.findOne(query, [token]); - if (!authToken || isTokenExpired(authToken.created, authToken.ttl)) + if (!auth || isTokenExpired(auth.created, auth.ttl)) throw new Error('Invalid authorization token'); - request.body.auth = { - userId: authToken.userId, - token: authorization + const args = Object.assign({}, req.query); + const props = Object.assign(args, req.body); + props.authorization = auth.id; + + req.args = props; + req.args.auth = { + userId: auth.userId, + token: auth.id, + email: auth.email, + lang: auth.lang }; next(); @@ -41,12 +51,9 @@ module.exports = app => { function getToken(request) { const headers = request.headers; - const params = request.query; + const queryParams = request.query; - if (headers.authorization) - params.authorization = headers.authorization; - - return headers.authorization || params.authorization; + return headers.authorization || queryParams.authorization; } function isTokenExpired(created, ttl) { diff --git a/print/core/smtp.js b/print/core/smtp.js index b274eafa3..23d19cabc 100644 --- a/print/core/smtp.js +++ b/print/core/smtp.js @@ -27,7 +27,7 @@ module.exports = { await db.rawSql(` INSERT INTO vn.mail (sender, replyTo, sent, subject, body, status) VALUES (:recipient, :sender, 1, :subject, :body, :status)`, { - sender: config.app.senderEmail, + sender: options.replyTo, recipient: options.to, subject: options.subject, body: options.text || options.html, diff --git a/print/methods/email.js b/print/methods/email.js index a56798820..69f880a0a 100644 --- a/print/methods/email.js +++ b/print/methods/email.js @@ -2,19 +2,11 @@ const Email = require('../core/email'); module.exports = app => { app.get(`/api/email/:name`, async(req, res, next) => { - const args = req.query; - const requiredArgs = ['clientId', 'recipient']; - const argList = requiredArgs.join(','); - const hasRequiredArgs = requiredArgs.every(arg => { - return args[arg]; - }); - try { - if (!hasRequiredArgs) - throw new Error(`Required properties not found [${argList}]`); + const reportName = req.params.name; + const email = new Email(reportName, req.args); - const email = new Email(req.params.name, args); - if (args.isPreview === 'true') { + if (req.args.isPreview === 'true') { const rendered = await email.render(); res.send(rendered); diff --git a/print/methods/report.js b/print/methods/report.js index 52d97912b..348c05ff3 100644 --- a/print/methods/report.js +++ b/print/methods/report.js @@ -2,15 +2,10 @@ const Report = require('../core/report'); module.exports = app => { app.get(`/api/report/:name`, async(req, res, next) => { - const query = req.query; - const body = re.body; - const args = Object.assign({}, req.query); - // merge params - try { const reportName = req.params.name; - const fileName = getFileName(reportName, args); - const report = new Report(reportName, args); + const fileName = getFileName(reportName, req.args); + const report = new Report(reportName, req.args); const stream = await report.toPdfStream(); res.setHeader('Content-type', 'application/pdf'); @@ -33,8 +28,7 @@ module.exports = app => { const keys = Object.keys(args); for (let arg of keys) { - // FIXME: #2197 - Remove clientId as a required param - if (arg != 'clientId' && arg.endsWith('Id')) + if (arg.endsWith('Id')) identifiers.push(arg); } diff --git a/print/templates/email/buyer-week-waste/buyer-week-waste.html b/print/templates/email/buyer-week-waste/buyer-week-waste.html index b9ebd6175..1183e0ac2 100644 --- a/print/templates/email/buyer-week-waste/buyer-week-waste.html +++ b/print/templates/email/buyer-week-waste/buyer-week-waste.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/campaign-metrics/campaign-metrics.html b/print/templates/email/campaign-metrics/campaign-metrics.html index 238d80d4a..4ba95adb9 100644 --- a/print/templates/email/campaign-metrics/campaign-metrics.html +++ b/print/templates/email/campaign-metrics/campaign-metrics.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/claim-pickup-order/claim-pickup-order.html b/print/templates/email/claim-pickup-order/claim-pickup-order.html index b00338467..cdde0dd92 100644 --- a/print/templates/email/claim-pickup-order/claim-pickup-order.html +++ b/print/templates/email/claim-pickup-order/claim-pickup-order.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/client-welcome/client-welcome.html b/print/templates/email/client-welcome/client-welcome.html index c5f203621..1d21846d7 100644 --- a/print/templates/email/client-welcome/client-welcome.html +++ b/print/templates/email/client-welcome/client-welcome.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/delivery-note-link/delivery-note-link.html b/print/templates/email/delivery-note-link/delivery-note-link.html index 28dbc7922..78fa2c922 100644 --- a/print/templates/email/delivery-note-link/delivery-note-link.html +++ b/print/templates/email/delivery-note-link/delivery-note-link.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/delivery-note/delivery-note.html b/print/templates/email/delivery-note/delivery-note.html index 0ee59a26f..71de29a3e 100644 --- a/print/templates/email/delivery-note/delivery-note.html +++ b/print/templates/email/delivery-note/delivery-note.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/driver-route/driver-route.html b/print/templates/email/driver-route/driver-route.html index b9d0aeab5..815b28b8c 100644 --- a/print/templates/email/driver-route/driver-route.html +++ b/print/templates/email/driver-route/driver-route.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.html b/print/templates/email/letter-debtor-nd/letter-debtor-nd.html index c7a6faebc..630cce8a2 100644 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.html +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.html b/print/templates/email/letter-debtor-st/letter-debtor-st.html index d277d363a..1fc61a478 100644 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.html +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.html @@ -1,5 +1,5 @@ - + @@ -23,7 +23,7 @@
-

{{ $t('title') }}

+

{{ $t('title') }} {{$i18n.locale}}

{{ $t('sections.introduction.title') }},

{{ $t('sections.introduction.description') }}

diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 61f3c01ad..8914c8320 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -37,9 +37,6 @@ module.exports = { 'attachment': attachment.build() }, props: { - authorization: { - required: true - }, clientId: { required: true }, diff --git a/print/templates/email/payment-update/payment-update.html b/print/templates/email/payment-update/payment-update.html index 6bba77308..0838d6efb 100644 --- a/print/templates/email/payment-update/payment-update.html +++ b/print/templates/email/payment-update/payment-update.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/printer-setup/printer-setup.html b/print/templates/email/printer-setup/printer-setup.html index 6b295bd8f..df0b43f0c 100644 --- a/print/templates/email/printer-setup/printer-setup.html +++ b/print/templates/email/printer-setup/printer-setup.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/email/printer-setup/printer-setup.js b/print/templates/email/printer-setup/printer-setup.js index 86ae0044a..320ce8cbd 100755 --- a/print/templates/email/printer-setup/printer-setup.js +++ b/print/templates/email/printer-setup/printer-setup.js @@ -13,6 +13,9 @@ module.exports = { data() { return {attachments}; }, + getClient() { + return this.clientId; + }, methods: { fetchClient(clientId) { return db.findOne(` @@ -29,6 +32,9 @@ module.exports = { LEFT JOIN worker w ON w.id = c.salesPersonFk LEFT JOIN account.user wu ON wu.id = w.userFk WHERE c.id = ?`, [clientId]); + }, + getClient() { + return this.clientId; } }, components: { diff --git a/print/templates/email/sepa-core/sepa-core.html b/print/templates/email/sepa-core/sepa-core.html index b71c8e10f..853597bf8 100644 --- a/print/templates/email/sepa-core/sepa-core.html +++ b/print/templates/email/sepa-core/sepa-core.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.html b/print/templates/reports/campaign-metrics/campaign-metrics.html index ee1908164..d125ab7e2 100644 --- a/print/templates/reports/campaign-metrics/campaign-metrics.html +++ b/print/templates/reports/campaign-metrics/campaign-metrics.html @@ -1,5 +1,5 @@ - + diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.html b/print/templates/reports/claim-pickup-order/claim-pickup-order.html index f23ee3401..59647cf9a 100644 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.html +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.html @@ -1,5 +1,5 @@ - +
diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 719397c08..9505cce29 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -1,5 +1,5 @@ - +
diff --git a/print/templates/reports/driver-route/driver-route.html b/print/templates/reports/driver-route/driver-route.html index ba9a339da..6ad027d83 100644 --- a/print/templates/reports/driver-route/driver-route.html +++ b/print/templates/reports/driver-route/driver-route.html @@ -1,5 +1,5 @@ - +
diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index 5ee45787c..fa8ad41a9 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -1,5 +1,5 @@ - +
diff --git a/print/templates/reports/item-label/item-label.html b/print/templates/reports/item-label/item-label.html index 0cb351b27..3f2d7ce69 100644 --- a/print/templates/reports/item-label/item-label.html +++ b/print/templates/reports/item-label/item-label.html @@ -1,5 +1,5 @@ - +
diff --git a/print/templates/reports/letter-debtor/letter-debtor.html b/print/templates/reports/letter-debtor/letter-debtor.html index 534798f5e..81a001765 100644 --- a/print/templates/reports/letter-debtor/letter-debtor.html +++ b/print/templates/reports/letter-debtor/letter-debtor.html @@ -1,5 +1,5 @@ - +
diff --git a/print/templates/reports/receipt/receipt.html b/print/templates/reports/receipt/receipt.html index 5538b7c3f..9a4e1964c 100644 --- a/print/templates/reports/receipt/receipt.html +++ b/print/templates/reports/receipt/receipt.html @@ -1,5 +1,5 @@ - +
diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index 720f70058..d14a3ce6e 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -1,5 +1,5 @@ - +
diff --git a/print/templates/reports/zone/zone.html b/print/templates/reports/zone/zone.html index 8e6406ad4..c1e8d1ec1 100644 --- a/print/templates/reports/zone/zone.html +++ b/print/templates/reports/zone/zone.html @@ -1,5 +1,5 @@ - +