1878 - Implementar autenticación en servicio print
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2020-03-05 13:56:45 +01:00
parent bc422e7f38
commit 1f714718bb
15 changed files with 96 additions and 59 deletions

View File

@ -108,7 +108,10 @@ function runFn(
$filter, $filter,
$interpolate, $interpolate,
$window, $window,
vnApp) { vnApp,
vnToken,
vnConfig,
aclService) {
Object.assign(Component.prototype, { Object.assign(Component.prototype, {
$translate, $translate,
$q, $q,
@ -121,7 +124,10 @@ function runFn(
$filter, $filter,
$interpolate, $interpolate,
$window, $window,
vnApp vnApp,
vnToken,
vnConfig,
aclService
}); });
} }
runFn.$inject = [ runFn.$inject = [
@ -136,7 +142,10 @@ runFn.$inject = [
'$filter', '$filter',
'$interpolate', '$interpolate',
'$window', '$window',
'vnApp' 'vnApp',
'vnToken',
'vnConfig',
'aclService'
]; ];
ngModule.run(runFn); ngModule.run(runFn);

View File

@ -155,7 +155,6 @@ class Controller {
}); });
} }
onUpdateGreugeResponse(response) { onUpdateGreugeResponse(response) {
if (response == 'accept') { if (response == 'accept') {
const promises = []; const promises = [];

View File

@ -1,14 +1,11 @@
import ngModule from '../module'; import ngModule from '../module';
import Component from 'core/lib/component';
class Controller { class Controller extends Component {
constructor($scope, $state, $http, $translate, vnApp, aclService, $httpParamSerializer) { constructor($element, $scope, $httpParamSerializer) {
this.$scope = $scope; super($element, $scope);
this.$state = $state;
this.$http = $http;
this.$translate = $translate;
this.vnApp = vnApp;
this.aclService = aclService;
this.$httpParamSerializer = $httpParamSerializer; this.$httpParamSerializer = $httpParamSerializer;
this.moreOptions = [ this.moreOptions = [
{callback: this.showPickupOrder, name: 'Show Pickup order'}, {callback: this.showPickupOrder, name: 'Show Pickup order'},
{callback: this.confirmPickupOrder, name: 'Send Pickup order'}, {callback: this.confirmPickupOrder, name: 'Send Pickup order'},
@ -22,7 +19,7 @@ class Controller {
return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl]));
}); });
this.$scope.moreButton.data = options; this.$.moreButton.data = options;
} }
onMoreChange(callback) { onMoreChange(callback) {
@ -63,7 +60,8 @@ class Controller {
showPickupOrder() { showPickupOrder() {
const params = { const params = {
clientId: this.claim.clientFk, clientId: this.claim.clientFk,
claimId: this.claim.id claimId: this.claim.id,
authorization: this.vnToken.token
}; };
const serializedParams = this.$httpParamSerializer(params); const serializedParams = this.$httpParamSerializer(params);
let url = `api/report/claim-pickup-order?${serializedParams}`; let url = `api/report/claim-pickup-order?${serializedParams}`;
@ -71,7 +69,7 @@ class Controller {
} }
confirmPickupOrder() { confirmPickupOrder() {
this.$scope.confirmPickupOrder.show(); this.$.confirmPickupOrder.show();
} }
sendPickupOrder(response) { sendPickupOrder(response) {
@ -81,16 +79,14 @@ class Controller {
clientId: this.claim.clientFk, clientId: this.claim.clientFk,
claimId: this.claim.id claimId: this.claim.id
}; };
const serializedParams = this.$httpParamSerializer(params); this.$http.get(`email/claim-pickup-order`, {params}).then(
const url = `email/claim-pickup-order?${serializedParams}`;
this.$http.get(url).then(
() => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) () => this.vnApp.showMessage(this.$translate.instant('Notification sent!'))
); );
} }
} }
confirmDeleteClaim() { confirmDeleteClaim() {
this.$scope.confirmDeleteClaim.show(); this.$.confirmDeleteClaim.show();
} }
deleteClaim(response) { deleteClaim(response) {
@ -103,7 +99,7 @@ class Controller {
} }
} }
Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp', 'aclService', '$httpParamSerializer']; Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
ngModule.component('vnClaimDescriptor', { ngModule.component('vnClaimDescriptor', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -191,7 +191,6 @@ module.exports = Self => {
if (socialNameChanged && !isAlpha(changes.socialName)) if (socialNameChanged && !isAlpha(changes.socialName))
throw new UserError('The socialName has an invalid format'); throw new UserError('The socialName has an invalid format');
if (changes.salesPerson === null) { if (changes.salesPerson === null) {
changes.credit = 0; changes.credit = 0;
changes.discount = 0; changes.discount = 0;
@ -238,7 +237,9 @@ module.exports = Self => {
const httpCtx = {req: loopBackContext.active}; const httpCtx = {req: loopBackContext.active};
const httpRequest = httpCtx.req.http.req; const httpRequest = httpCtx.req.http.req;
const $t = httpRequest.__; const $t = httpRequest.__;
const origin = httpRequest.headers.origin; const headers = httpRequest.headers;
const origin = headers.origin;
const authorization = headers.authorization;
const salesPersonId = instance.salesPersonFk; const salesPersonId = instance.salesPersonFk;
@ -254,12 +255,14 @@ module.exports = Self => {
// Send email to client // Send email to client
if (!instance.email) return; if (!instance.email) return;
const serializedParams = httpParamSerializer({ const params = {
authorization: authorization,
clientId: instance.id, clientId: instance.id,
recipient: instance.email recipient: instance.email
};
await request.get(`${origin}/api/email/payment-update`, {
qs: params
}); });
const query = `${origin}/api/email/payment-update?${serializedParams}`;
await request.get(query);
} }
}); });

View File

@ -5,6 +5,7 @@ class Controller extends Component {
constructor($element, $, $httpParamSerializer) { constructor($element, $, $httpParamSerializer) {
super($element, $); super($element, $);
this.$httpParamSerializer = $httpParamSerializer; this.$httpParamSerializer = $httpParamSerializer;
this.moreOptions = [ this.moreOptions = [
{name: 'Simple ticket', callback: this.newTicket}, {name: 'Simple ticket', callback: this.newTicket},
{name: 'Send SMS', callback: this.showSMSDialog}, {name: 'Send SMS', callback: this.showSMSDialog},
@ -72,8 +73,13 @@ class Controller extends Component {
sendConsumerReport(response) { sendConsumerReport(response) {
if (response === 'accept') { if (response === 'accept') {
const data = {from: this.from, to: this.to, clientId: this.client.id}; const params = {
const serializedParams = this.$httpParamSerializer(data); authorization: this.vnToken.token,
clientId: this.client.id,
from: this.from,
to: this.to,
};
const serializedParams = this.$httpParamSerializer(params);
const url = `api/report/campaign-metrics?${serializedParams}`; const url = `api/report/campaign-metrics?${serializedParams}`;
window.open(url); window.open(url);
} }

View File

@ -2,10 +2,10 @@ import ngModule from '../module';
import Component from 'core/lib/component'; import Component from 'core/lib/component';
class Controller extends Component { class Controller extends Component {
constructor($element, $, $httpParamSerializer, vnConfig) { constructor($element, $, $httpParamSerializer) {
super($element, $); super($element, $);
this.vnConfig = vnConfig;
this.$httpParamSerializer = $httpParamSerializer; this.$httpParamSerializer = $httpParamSerializer;
this.moreOptions = [ this.moreOptions = [
{name: 'Show entry report', callback: this.showEntryReport} {name: 'Show entry report', callback: this.showEntryReport}
]; ];
@ -59,6 +59,7 @@ class Controller extends Component {
showEntryReport() { showEntryReport() {
const params = { const params = {
authorization: this.vnToken.token,
clientId: this.vnConfig.storage.currentUserWorkerId, clientId: this.vnConfig.storage.currentUserWorkerId,
entryId: this.entry.id entryId: this.entry.id
}; };
@ -68,7 +69,7 @@ class Controller extends Component {
} }
} }
Controller.$inject = ['$element', '$scope', '$httpParamSerializer', 'vnConfig']; Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
ngModule.component('vnEntryDescriptor', { ngModule.component('vnEntryDescriptor', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -1,12 +1,10 @@
import ngModule from '../module'; import ngModule from '../module';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $scope, $httpParamSerializer) {
super($element, $scope);
class Controller {
constructor($, $http, vnApp, $translate, aclService, $httpParamSerializer) {
this.$http = $http;
this.vnApp = vnApp;
this.$translate = $translate;
this.$ = $;
this.aclService = aclService;
this.$httpParamSerializer = $httpParamSerializer; this.$httpParamSerializer = $httpParamSerializer;
this.moreOptions = [ this.moreOptions = [
{callback: this.showRouteReport, name: 'Show route report'}, {callback: this.showRouteReport, name: 'Show route report'},
@ -39,6 +37,7 @@ class Controller {
showRouteReport() { showRouteReport() {
const user = this.route.worker.user; const user = this.route.worker.user;
const params = { const params = {
authorization: this.vnToken.token,
clientId: user.id, clientId: user.id,
routeId: this.route.id routeId: this.route.id
}; };
@ -54,9 +53,7 @@ class Controller {
clientId: user.id, clientId: user.id,
routeId: this.route.id routeId: this.route.id
}; };
const serializedParams = this.$httpParamSerializer(params); this.$http.get(`email/driver-route`, {params}).then(() => {
const url = `email/driver-route?${serializedParams}`;
this.$http.get(url).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Report sent')); this.vnApp.showSuccess(this.$translate.instant('Report sent'));
}); });
} }
@ -76,7 +73,7 @@ class Controller {
} }
} }
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', 'aclService', '$httpParamSerializer']; Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
ngModule.component('vnRouteDescriptor', { ngModule.component('vnRouteDescriptor', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -2,10 +2,10 @@ import ngModule from '../module';
import Component from 'core/lib/component'; import Component from 'core/lib/component';
class Controller extends Component { class Controller extends Component {
constructor($element, $, aclService, $httpParamSerializer) { constructor($element, $, $httpParamSerializer) {
super($element, $); super($element, $);
this.aclService = aclService;
this.$httpParamSerializer = $httpParamSerializer; this.$httpParamSerializer = $httpParamSerializer;
this.moreOptions = [ this.moreOptions = [
{ {
name: 'Add turn', name: 'Add turn',
@ -220,7 +220,8 @@ class Controller extends Component {
showDeliveryNote() { showDeliveryNote() {
const params = { const params = {
clientId: this.ticket.client.id, clientId: this.ticket.client.id,
ticketId: this.ticket.id ticketId: this.ticket.id,
authorization: this.vnToken.token
}; };
const serializedParams = this.$httpParamSerializer(params); const serializedParams = this.$httpParamSerializer(params);
let url = `api/report/delivery-note?${serializedParams}`; let url = `api/report/delivery-note?${serializedParams}`;
@ -332,7 +333,7 @@ class Controller extends Component {
} }
} }
Controller.$inject = ['$element', '$scope', 'aclService', '$httpParamSerializer']; Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
ngModule.component('vnTicketDescriptor', { ngModule.component('vnTicketDescriptor', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -3,3 +3,5 @@ require('./date');
require('./uppercase'); require('./uppercase');
require('./currency'); require('./currency');
require('./percentage'); require('./percentage');
require('./number');

View File

@ -0,0 +1,10 @@
const Vue = require('vue');
const config = require('../config');
const defaultLocale = config.i18n.locale;
Vue.filter('number', function(value, locale = defaultLocale) {
if (!locale) locale = defaultLocale;
return new Intl.NumberFormat(locale, {
style: 'decimal'
}).format(parseFloat(value));
});

View File

@ -21,7 +21,6 @@ module.exports = app => {
const authorization = getToken(request); const authorization = getToken(request);
const query = `SELECT userId, ttl, created const query = `SELECT userId, ttl, created
FROM salix.AccessToken WHERE id = ?`; FROM salix.AccessToken WHERE id = ?`;
console.log('auth');
try { try {
const authToken = await db.findOne(query, [authorization]); const authToken = await db.findOne(query, [authorization]);
@ -36,17 +35,25 @@ module.exports = app => {
}); });
function getToken(request) { function getToken(request) {
return request.headers.authorization || request.query.authorization; const headers = request.headers;
const params = request.query;
if (headers.authorization)
params.authorization = headers.authorization;
return headers.authorization || params.authorization;
} }
function isTokenExpired(created, ttl) { function isTokenExpired(created, ttl) {
let date = new Date(created); const date = new Date(created);
let currentDate = new Date(); const currentDate = new Date();
date.setSeconds(date.getSeconds() + ttl); date.setSeconds(date.getSeconds() + ttl);
if (currentDate > date) if (currentDate > date)
return true; return true;
return false;
} }
// Mount methods // Mount methods

View File

@ -37,6 +37,9 @@ module.exports = {
'attachment': attachment.build() 'attachment': attachment.build()
}, },
props: { props: {
authorization: {
required: true
},
clientId: { clientId: {
required: true required: true
}, },

View File

@ -37,11 +37,14 @@ module.exports = {
'attachment': attachment.build() 'attachment': attachment.build()
}, },
props: { props: {
authorization: {
required: true
},
clientId: { clientId: {
required: true required: true
}, },
companyId: { companyId: {
required: true required: true
} },
} }
}; };

View File

@ -61,7 +61,7 @@
<th>{{$t('reference')}}</th> <th>{{$t('reference')}}</th>
<th class="number">{{$t('quantity')}}</th> <th class="number">{{$t('quantity')}}</th>
<th class="number">{{$t('claims')}}</th> <th class="number">{{$t('claims')}}</th>
<th>{{$t('concept')}}</th> <th width="50%">{{$t('concept')}}</th>
</tr> </tr>
</thead> </thead>
<tbody v-for="sale in sales" v-bind:key="sale.id"> <tbody v-for="sale in sales" v-bind:key="sale.id">
@ -69,7 +69,7 @@
<td class="font gray">{{sale.id}}</td> <td class="font gray">{{sale.id}}</td>
<td class="number">{{sale.quantity}}</td> <td class="number">{{sale.quantity}}</td>
<td class="number">{{sale.claimQuantity}}</td> <td class="number">{{sale.claimQuantity}}</td>
<td>{{sale.concept}}</td> <td width="50%">{{sale.concept}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -63,12 +63,12 @@
<table class="column-oriented"> <table class="column-oriented">
<thead> <thead>
<tr> <tr>
<td>{{$t('boxes')}}</td> <td class="number">{{$t('boxes')}}</td>
<td class="number">{{$t('packing')}}</td> <td class="number">{{$t('packing')}}</td>
<td width="50%">{{$t('concept')}}</td> <td width="50%">{{$t('concept')}}</td>
<td class="number">{{$t('quantity')}}</td> <td width="10%" class="number">{{$t('quantity')}}</td>
<td class="number">{{$t('price')}}</td> <td width="15%" class="number">{{$t('price')}}</td>
<td class="number">{{$t('amount')}}</td> <td width="15%" class="number">{{$t('amount')}}</td>
</tr> </tr>
</thead> </thead>
<tbody v-for="buy in buys"> <tbody v-for="buy in buys">
@ -76,9 +76,9 @@
<td class="number">{{buy.box}}</td> <td class="number">{{buy.box}}</td>
<td class="number">{{buy.packing}}</td> <td class="number">{{buy.packing}}</td>
<td width="50%">{{buy.itemName}}</td> <td width="50%">{{buy.itemName}}</td>
<td class="number">{{buy.quantity}}</td> <td width="10%" class="number">{{buy.quantity | number}}</td>
<td class="number">{{buy.buyingValue | currency('EUR', locale)}}</td> <td width="15%" class="number">{{buy.buyingValue | currency('EUR', locale)}}</td>
<td class="number">{{buy.buyingValue * buy.quantity | currency('EUR', locale)}}</td> <td width="15%" class="number">{{buy.buyingValue * buy.quantity | currency('EUR', locale)}}</td>
</tr> </tr>
<tr class="description"> <tr class="description">
<td colspan="2"> <td colspan="2">