Attachments refactor
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2022-10-04 13:41:37 +02:00
parent eadff3fff9
commit 377a0f7228
29 changed files with 347 additions and 50 deletions

View File

@ -8,18 +8,22 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
('Client', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'campaignMetricsEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'clientWelcomeHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'clientWelcomeEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),,
('Client', 'clientWelcomeEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'creditRequestPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'creditRequestHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'creditRequestEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'printerSetupHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'printerSetupEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'sepaCoreEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'letterDebtorPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'letterDebtorStHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'letterDebtorStEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'letterDebtorNdHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'letterDebtorNdEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'clientDebtStatementPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'clientDebtStatementHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'clientDebtStatementEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'incotermsAuthorizationPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'incotermsAuthorizationHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Client', 'incotermsAuthorizationEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('Client', 'consumptionSendQueued', 'WRITE', 'ALLOW', 'ROLE', 'system'),

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Item index path', () => {
fdescribe('Item index path', () => {
let browser;
let page;
beforeAll(async() => {

View File

@ -46,6 +46,7 @@ module.exports = Self => {
});
Self.clientDebtStatementHtml = async(ctx, id) => {
const {accessToken} = ctx.req;
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
@ -54,6 +55,7 @@ module.exports = Self => {
params[param] = args[param];
params.isPreview = true;
params.access_token = accessToken.id;
const report = new Email('client-debt-statement', params);
const html = await report.render();

View File

@ -0,0 +1,61 @@
const {Report} = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('clientDebtStatementPdf', {
description: 'Returns the client debt statement pdf',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The client id',
http: {source: 'path'}
},
{
arg: 'recipientId',
type: 'number',
description: 'The recipient id',
required: false
},
{
arg: 'from',
type: 'string',
required: true
}
],
returns: [
{
arg: 'body',
type: 'file',
root: true
}, {
arg: 'Content-Type',
type: 'String',
http: {target: 'header'}
}, {
arg: 'Content-Disposition',
type: 'String',
http: {target: 'header'}
}
],
http: {
path: '/:id/client-debt-statement-pdf',
verb: 'GET'
}
});
Self.clientDebtStatementPdf = async(ctx, id) => {
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
delete args.ctx;
for (const param in args)
params[param] = args[param];
const report = new Report('client-debt-statement', params);
const stream = await report.toPdfStream();
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
};
};

View File

@ -41,6 +41,7 @@ module.exports = Self => {
});
Self.creditRequestHtml = async(ctx, id) => {
const {accessToken} = ctx.req;
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
@ -49,6 +50,7 @@ module.exports = Self => {
params[param] = args[param];
params.isPreview = true;
params.access_token = accessToken.id;
const report = new Email('credit-request', params);
const html = await report.render();

View File

@ -0,0 +1,56 @@
const {Report} = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('creditRequestPdf', {
description: 'Returns the credit request pdf',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The client id',
http: {source: 'path'}
},
{
arg: 'recipientId',
type: 'number',
description: 'The recipient id',
required: false
}
],
returns: [
{
arg: 'body',
type: 'file',
root: true
}, {
arg: 'Content-Type',
type: 'String',
http: {target: 'header'}
}, {
arg: 'Content-Disposition',
type: 'String',
http: {target: 'header'}
}
],
http: {
path: '/:id/credit-request-pdf',
verb: 'GET'
}
});
Self.creditRequestPdf = async(ctx, id) => {
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
delete args.ctx;
for (const param in args)
params[param] = args[param];
const report = new Report('credit-request', params);
const stream = await report.toPdfStream();
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
};
};

View File

@ -47,6 +47,7 @@ module.exports = Self => {
});
Self.incotermsAuthorizationHtml = async(ctx, id) => {
const {accessToken} = ctx.req;
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
@ -55,6 +56,7 @@ module.exports = Self => {
params[param] = args[param];
params.isPreview = true;
params.access_token = accessToken.id;
const report = new Email('incoterms-authorization', params);
const html = await report.render();

View File

@ -0,0 +1,62 @@
const {Report} = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('incotermsAuthorizationPdf', {
description: 'Returns the incoterms authorization pdf',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The client id',
http: {source: 'path'}
},
{
arg: 'recipientId',
type: 'number',
description: 'The recipient id',
required: false
},
{
arg: 'companyId',
type: 'number',
description: 'The company id',
required: true
}
],
returns: [
{
arg: 'body',
type: 'file',
root: true
}, {
arg: 'Content-Type',
type: 'String',
http: {target: 'header'}
}, {
arg: 'Content-Disposition',
type: 'String',
http: {target: 'header'}
}
],
http: {
path: '/:id/incoterms-authorization-pdf',
verb: 'GET'
}
});
Self.incotermsAuthorizationPdf = async(ctx, id) => {
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
delete args.ctx;
for (const param in args)
params[param] = args[param];
const report = new Report('incoterms-authorization', params);
const stream = await report.toPdfStream();
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
};
};

View File

@ -47,6 +47,7 @@ module.exports = Self => {
});
Self.letterDebtorNdHtml = async(ctx, id) => {
const {accessToken} = ctx.req;
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
@ -55,6 +56,7 @@ module.exports = Self => {
params[param] = args[param];
params.isPreview = true;
params.access_token = accessToken.id;
const report = new Email('letter-debtor-nd', params);
const html = await report.render();

View File

@ -0,0 +1,62 @@
const {Report} = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('letterDebtorPdf', {
description: 'Returns the letter debtor pdf',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The client id',
http: {source: 'path'}
},
{
arg: 'recipientId',
type: 'number',
description: 'The recipient id',
required: false
},
{
arg: 'companyId',
type: 'number',
description: 'The company id',
required: true
}
],
returns: [
{
arg: 'body',
type: 'file',
root: true
}, {
arg: 'Content-Type',
type: 'String',
http: {target: 'header'}
}, {
arg: 'Content-Disposition',
type: 'String',
http: {target: 'header'}
}
],
http: {
path: '/:id/letter-debtor-pdf',
verb: 'GET'
}
});
Self.letterDebtorPdf = async(ctx, id) => {
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
delete args.ctx;
for (const param in args)
params[param] = args[param];
const report = new Report('letter-debtor', params);
const stream = await report.toPdfStream();
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
};
};

View File

@ -47,6 +47,7 @@ module.exports = Self => {
});
Self.letterDebtorStHtml = async(ctx, id) => {
const {accessToken} = ctx.req;
const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()};
@ -55,6 +56,7 @@ module.exports = Self => {
params[param] = args[param];
params.isPreview = true;
params.access_token = accessToken.id;
const report = new Email('letter-debtor-st', params);
const html = await report.render();

View File

@ -32,14 +32,18 @@ module.exports = Self => {
require('../methods/client/printerSetupHtml')(Self);
require('../methods/client/printerSetupEmail')(Self);
require('../methods/client/sepaCoreEmail')(Self);
require('../methods/client/letterDebtorPdf')(Self);
require('../methods/client/letterDebtorStHtml')(Self);
require('../methods/client/letterDebtorStEmail')(Self);
require('../methods/client/letterDebtorNdHtml')(Self);
require('../methods/client/letterDebtorNdEmail')(Self);
require('../methods/client/clientDebtStatementPdf')(Self);
require('../methods/client/clientDebtStatementHtml')(Self);
require('../methods/client/clientDebtStatementEmail')(Self);
require('../methods/client/creditRequestPdf')(Self);
require('../methods/client/creditRequestHtml')(Self);
require('../methods/client/creditRequestEmail')(Self);
require('../methods/client/incotermsAuthorizationPdf')(Self);
require('../methods/client/incotermsAuthorizationHtml')(Self);
require('../methods/client/incotermsAuthorizationEmail')(Self);
require('../methods/client/consumptionSendQueued')(Self);

View File

@ -21,4 +21,14 @@ vn-item-product {
vn-label-value:first-of-type section{
margin-top: 9px;
}
}
vn-item-index {
table {
img {
border-radius: 50%;
width: 50px;
height: 50px;
}
}
}

View File

@ -31,3 +31,8 @@ h1 {
font-weight: 100;
font-size: 1.5em
}
h6 {
font-weight: 100;
font-size: 1.2em
}

View File

@ -4,19 +4,22 @@ div {
}
a {
background-color: #F5F5F5;
background-color: #fcfcfc;
border: 1px solid #CCC;
display: flex;
vertical-align: middle;
box-sizing: border-box;
min-width: 150px;
text-decoration: none;
border-radius: 3px;
border-radius: 8px;
color: #8dba25
}
a > div.icon {
border-radius: 5px;
padding: 2px 5px;
background-color: red;
font-weight: bold;
font-size: 18px;
color: #555
font-size: 12px;
color: #FFF
}

View File

@ -1,6 +1,10 @@
<div class="vn-mx-xs" v-if="attachment.component">
<div class="vn-mx-xs" v-if="attachment">
<a target="_blank" class="vn-py-sm vn-px-md" v-bind:href="attachmentPath">
<div
v-if="attachment.type && attachment.type == 'pdf'"
class="icon vn-mr-sm">
PDF
</div>
<div class="text">{{attachment.filename}}</div>
<div class="icon vn-pl-md">&#x25BC;</div>
</a>
</div>

View File

@ -4,10 +4,10 @@ module.exports = {
attachmentPath() {
const filename = this.attachment.filename;
const component = this.attachment.component;
if (this.attachment.cid)
if (this.attachment.cid && component)
return `/api/${component}/assets/files/${filename}`;
else
return `/api/report/${component}?${this.getHttpParams()}`;
else if (this.attachment.path)
return `/api/${this.attachment.path}?${this.getHttpParams()}`;
}
},
methods: {
@ -15,7 +15,7 @@ module.exports = {
const props = this.args;
let query = '';
for (let param in props) {
if (!(props[param] instanceof Object)) {
if (props[param] && !(props[param] instanceof Object)) {
if (query != '') query += '&';
query += `${param}=${props[param]}`;
}

View File

@ -1,6 +1,5 @@
const path = require('path');
const smtp = require('./smtp');
const config = require('./config');
const Component = require('./component');
const Report = require('./report');

View File

@ -4,7 +4,7 @@ const validator = {
const props = this.$options.props;
const invalidProps = [];
for (prop in props) {
for (const prop in props) {
const isObject = typeof props[prop] === 'object';
const isRequired = props[prop].required;
const isNotDefined = this[prop] === undefined;
@ -19,7 +19,7 @@ const validator = {
throw new Error(`Required properties not found [${required}]`);
}
},
props: ['isPreview', 'authorization']
props: ['isPreview', 'access_token']
};
Vue.mixin(validator);

View File

@ -24,7 +24,7 @@ const userLocale = {
});
}
},
props: ['auth', 'recipientId']
props: ['recipientId']
};
Vue.mixin(userLocale);

View File

@ -1,6 +0,0 @@
[
{
"filename": "client-debt-statement.pdf",
"component": "client-debt-statement"
}
]

View File

@ -2,7 +2,6 @@ const Component = require(`vn-print/core/component`);
const emailHeader = new Component('email-header');
const emailFooter = new Component('email-footer');
const attachment = new Component('attachment');
const attachments = require('./attachments.json');
module.exports = {
name: 'client-debt-statement',
@ -12,7 +11,15 @@ module.exports = {
'attachment': attachment.build()
},
data() {
return {attachments};
return {
attachments: [
{
filename: 'client-debt-statement.pdf',
type: 'pdf',
path: `Clients/${this.id}/client-debt-statement-pdf`
}
]
};
},
props: {
id: {

View File

@ -2,7 +2,6 @@ const Component = require(`vn-print/core/component`);
const emailHeader = new Component('email-header');
const emailFooter = new Component('email-footer');
const attachment = new Component('attachment');
const attachments = require('./attachments.json');
module.exports = {
name: 'credit-request',
@ -12,6 +11,20 @@ module.exports = {
'attachment': attachment.build()
},
data() {
return {attachments};
return {
attachments: [
{
filename: 'credit-request.pdf',
type: 'pdf',
path: `Clients/${this.id}/credit-request-pdf`
}
]
};
},
props: {
id: {
type: Number,
required: true
}
}
};

View File

@ -1,6 +0,0 @@
[
{
"filename": "incoterms-authorization.pdf",
"component": "incoterms-authorization"
}
]

View File

@ -2,12 +2,19 @@ const Component = require(`vn-print/core/component`);
const emailHeader = new Component('email-header');
const emailFooter = new Component('email-footer');
const attachment = new Component('attachment');
const attachments = require('./attachments.json');
module.exports = {
name: 'incoterms-authorization',
data() {
return {attachments};
return {
attachments: [
{
filename: 'incoterms-authorization.pdf',
type: 'pdf',
path: `Clients/${this.id}/incoterms-authorization-pdf`
}
]
};
},
components: {
'email-header': emailHeader.build(),

View File

@ -1,6 +0,0 @@
[
{
"filename": "letter-debtor.pdf",
"component": "letter-debtor"
}
]

View File

@ -2,7 +2,6 @@ const Component = require(`vn-print/core/component`);
const emailHeader = new Component('email-header');
const emailFooter = new Component('email-footer');
const attachment = new Component('attachment');
const attachments = require('./attachments.json');
module.exports = {
name: 'letter-debtor-nd',
@ -13,7 +12,15 @@ module.exports = {
throw new Error('Something went wrong');
},
data() {
return {attachments};
return {
attachments: [
{
filename: 'letter-debtor.pdf',
type: 'pdf',
path: `Clients/${this.id}/letter-debtor-pdf`
}
]
};
},
methods: {
fetchDebtor(id, companyId) {

View File

@ -1,6 +0,0 @@
[
{
"filename": "letter-debtor.pdf",
"component": "letter-debtor"
}
]

View File

@ -2,7 +2,6 @@ const Component = require(`vn-print/core/component`);
const emailHeader = new Component('email-header');
const emailFooter = new Component('email-footer');
const attachment = new Component('attachment');
const attachments = require('./attachments.json');
module.exports = {
name: 'letter-debtor-st',
@ -13,7 +12,15 @@ module.exports = {
throw new Error('Something went wrong');
},
data() {
return {attachments};
return {
attachments: [
{
filename: 'letter-debtor.pdf',
type: 'pdf',
path: `Clients/${this.id}/letter-debtor-pdf`
}
]
};
},
methods: {
fetchDebtor(id, companyId) {