From 15a1965a5322e407071b183f0b5e3a6879a540c6 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 18 May 2023 14:12:46 +0200 Subject: [PATCH 1/2] refs #5094 add scopes --- back/methods/docuware/deliveryNoteEmail.js | 25 +++++++++++-------- modules/ticket/front/descriptor-menu/index.js | 3 ++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/back/methods/docuware/deliveryNoteEmail.js b/back/methods/docuware/deliveryNoteEmail.js index 1f9d7556f..9b6b5a181 100644 --- a/back/methods/docuware/deliveryNoteEmail.js +++ b/back/methods/docuware/deliveryNoteEmail.js @@ -4,25 +4,25 @@ module.exports = Self => { Self.remoteMethodCtx('deliveryNoteEmail', { description: 'Sends the delivery note email with an docuware attached PDF', accessType: 'WRITE', + accessScopes: ['docuwareDeliveryNoteEmail'], accepts: [ { arg: 'id', type: 'string', required: true, description: 'The ticket id', - http: {source: 'path'} - }, - { - arg: 'recipient', - type: 'string', - description: 'The recipient email', - required: true, }, { arg: 'recipientId', type: 'number', description: 'The client id', - required: false + required: true + }, + { + arg: 'recipient', + type: 'string', + description: 'The recipient email', + required: false, } ], returns: [ @@ -41,12 +41,13 @@ module.exports = Self => { } ], http: { - path: '/:id/delivery-note-email', + path: '/delivery-note-email', verb: 'POST' } }); - Self.deliveryNoteEmail = async(ctx, id) => { + Self.deliveryNoteEmail = async(ctx, id, recipientId, recipient) => { + const models = Self.app.models; const args = Object.assign({}, ctx.args); const params = { recipient: args.recipient, @@ -57,9 +58,11 @@ module.exports = Self => { for (const param in args) params[param] = args[param]; + if (!recipient) params.recipient = models.Client.findById(recipientId, {fields: ['email']}); + const email = new Email('delivery-note', params); - const docuwareFile = await Self.app.models.Docuware.download(ctx, id, 'deliveryNote'); + const docuwareFile = await models.Docuware.download(ctx, id, 'deliveryNote'); return email.send({ overrideAttachments: true, diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index e32363f09..987d6a3f1 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -142,9 +142,10 @@ class Controller extends Section { sendPdfDeliveryNote($data) { let query = `tickets/${this.id}/delivery-note-email`; - if (this.hasDocuwareFile) query = `docuwares/${this.id}/delivery-note-email`; + if (this.hasDocuwareFile) query = `docuwares/delivery-note-email`; return this.vnEmail.send(query, { + id: this.id, recipientId: this.ticket.client.id, recipient: $data.email }); -- 2.40.1 From f54d9180b1c48227cdc63a5963f1420cc846ad2c Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 18 May 2023 14:44:05 +0200 Subject: [PATCH 2/2] fix front test --- modules/ticket/front/descriptor-menu/index.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 48998325a..5d27acff1 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -141,6 +141,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { const $data = {email: 'brucebanner@gothamcity.com'}; const params = { + id: 16, recipient: $data.email, recipientId: ticket.client.id }; -- 2.40.1