From aef96597980c9ea90cca6c91a005faba2b2b508f Mon Sep 17 00:00:00 2001 From: Joan Date: Mon, 2 Oct 2017 11:19:55 +0200 Subject: [PATCH] =?UTF-8?q?Mailer:=20Autentificaci=C3=B3n=20token=20por=20?= =?UTF-8?q?ruta.=20Fix=20creditClassification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client/src/billing-data/billing-data.js | 2 +- client/client/src/billing-data/billing-data.spec.js | 4 ++-- services/client/common/methods/client/activate.js | 7 +++++-- services/mailer/application/route/manuscript.js | 10 ++++++++-- services/mailer/application/route/notification.js | 9 ++++++++- services/mailer/server.js | 8 -------- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/client/client/src/billing-data/billing-data.js b/client/client/src/billing-data/billing-data.js index 0b374fcbd..df281e8b3 100644 --- a/client/client/src/billing-data/billing-data.js +++ b/client/client/src/billing-data/billing-data.js @@ -41,7 +41,7 @@ export default class Controller { } returnDialog(response) { if (response === 'ACCEPT') { - this.$http.post(`/mailer/manuscript/${this.client.id}/payment-update`).then( + this.$http.post(`/mailer/manuscript/payment-update/${this.client.id}`).then( () => this.vnApp.showMessage(this.translate.instant('Notification sent!')) ); } diff --git a/client/client/src/billing-data/billing-data.spec.js b/client/client/src/billing-data/billing-data.spec.js index b4fc84051..6e3f2e849 100644 --- a/client/client/src/billing-data/billing-data.spec.js +++ b/client/client/src/billing-data/billing-data.spec.js @@ -75,8 +75,8 @@ describe('Client', () => { it('should request to send notification email', () => { let controller = $componentController('vnClientBillingData', {$scope: $scope}); controller.client = {id: '123'}; - $httpBackend.when('POST', `/mailer/manuscript/${controller.client.id}/payment-update`).respond('done'); - $httpBackend.expectPOST(`/mailer/manuscript/${controller.client.id}/payment-update`); + $httpBackend.when('POST', `/mailer/manuscript/payment-update/${controller.client.id}`).respond('done'); + $httpBackend.expectPOST(`/mailer/manuscript/payment-update/${controller.client.id}`); controller.returnDialog('ACCEPT'); $httpBackend.flush(); }); diff --git a/services/client/common/methods/client/activate.js b/services/client/common/methods/client/activate.js index 664e05d20..bfce30ea3 100644 --- a/services/client/common/methods/client/activate.js +++ b/services/client/common/methods/client/activate.js @@ -36,10 +36,13 @@ module.exports = function(Client) { let filter = {where: {clientFk: client.id}, fields: ['started', 'ended']}; - app.models.CreditClassification.findOne(filter, function(err, data) { + app.models.CreditClassification.findOne(filter, function(error, data) { + if (error) + return; + let currentDate = new Date(); - if (client.active && data.ended >= currentDate) { + if (data && client.active && (data.ended >= currentDate || data.ended == null)) { let host = ctx.req.headers.host.split(':')[0]; var options = { url: `http://${host}:5000/mailer/notification/client-deactivate/${client.id}`, diff --git a/services/mailer/application/route/manuscript.js b/services/mailer/application/route/manuscript.js index 5f24ed299..1ec5984c1 100644 --- a/services/mailer/application/route/manuscript.js +++ b/services/mailer/application/route/manuscript.js @@ -1,10 +1,16 @@ var express = require('express'); var router = new express.Router(); var mail = require('../mail.js'); +var auth = require('../auth.js'); + +// Auth middleware +var requestToken = function(request, response, next) { + auth.init(request, response, next); +}; // Payment method changes -router.post('/:recipient/payment-update', function(request, response, next) { - mail.sendWithTemplate('payment-update', {recipient: request.params.recipient}, result => { +router.post('/payment-update/:clientId', requestToken, function(request, response, next) { + mail.sendWithTemplate('payment-update', {recipient: request.params.clientId}, result => { return response.json(result); }); }); diff --git a/services/mailer/application/route/notification.js b/services/mailer/application/route/notification.js index acab692df..508aed386 100644 --- a/services/mailer/application/route/notification.js +++ b/services/mailer/application/route/notification.js @@ -3,6 +3,13 @@ var router = new express.Router(); var mail = require('../mail.js'); var database = require('../database.js'); var settings = require('../settings.js'); +var auth = require('../auth.js'); + +// Auth middleware +var requestToken = function(request, response, next) { + auth.init(request, response, next); +}; + // Single user notification /* router.post('/:recipient/noticeUserSend', function(request, response) { var params = { @@ -64,7 +71,7 @@ var settings = require('../settings.js'); }); */ // Send notification to alias solunion on client deactivate -router.post('/client-deactivate/:clientId', function(request, response) { +router.post('/client-deactivate/:clientId', requestToken, function(request, response) { var params = { alias: 'solunion', code: 'clientDeactivate', diff --git a/services/mailer/server.js b/services/mailer/server.js index 63a7c1596..dc93e525b 100644 --- a/services/mailer/server.js +++ b/services/mailer/server.js @@ -7,19 +7,11 @@ var bodyParser = require('body-parser'); var settings = require('./application/settings.js'); var mail = require('./application/mail.js'); var database = require('./application/database.js'); -var auth = require('./application/auth.js'); // Body parser middleware app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); -// Auth middleware -var requestToken = function(request, response, next) { - auth.init(request, response, next); -}; - -app.use(requestToken); - // Load routes app.use('/', require('./application/router.js'));