From 19d1ea47a0a5cf6a39e38d27c2b602f6d2259c9b Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 21 Jan 2022 11:40:48 +0100 Subject: [PATCH 1/4] feat(ticket_sale): role restriction to create payBack --- .../05-ticket/01-sale/02_edit_sale.spec.js | 4 +++ loopback/locale/es.json | 5 ++-- modules/ticket/back/methods/sale/payBack.js | 11 +++++++ .../{payment.spec.js => payBack.spec.js} | 30 ++++++++++++++++++- modules/ticket/front/sale/index.html | 4 ++- 5 files changed, 50 insertions(+), 4 deletions(-) rename modules/ticket/back/methods/sale/specs/{payment.spec.js => payBack.spec.js} (53%) diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 1f3aedadf..f5f290c50 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -207,6 +207,10 @@ describe('Ticket Edit sale path', () => { }); it('should select the third sale and create a pay back', async() => { + await page.loginAndModule('salesAssistant', 'ticket'); + await page.accessToSearchResult('16'); + await page.accessToSection('ticket.card.sale'); + await page.waitToClick(selectors.ticketSales.firstSaleCheckbox); await page.waitToClick(selectors.ticketSales.moreMenu); await page.waitToClick(selectors.ticketSales.moreMenuPayBack); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9ffae7997..4be9085db 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -216,5 +216,6 @@ "The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día", "The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día", "You can not modify is pay method checked": "No se puede modificar el campo método de pago validado", - "Can't transfer claimed sales": "No puedes transferir lineas reclamadas" - } \ No newline at end of file + "Can't transfer claimed sales": "No puedes transferir lineas reclamadas", + "You don't have privileges to create pay back": "No tienes permisos para crear un abono" +} \ No newline at end of file diff --git a/modules/ticket/back/methods/sale/payBack.js b/modules/ticket/back/methods/sale/payBack.js index 41150a1e0..a7f04b1be 100644 --- a/modules/ticket/back/methods/sale/payBack.js +++ b/modules/ticket/back/methods/sale/payBack.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { Self.remoteMethodCtx('payBack', { description: 'Create ticket with the selected lines changing the sign to the quantites', @@ -39,6 +41,15 @@ module.exports = Self => { try { const salesIds = []; const params = []; + const userId = ctx.req.accessToken.userId; + + const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager'); + const isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant'); + const checkRoles = isClaimManager || isSalesAssistant; + + if (!checkRoles) + throw new UserError(`You don't have privileges to create pay back`); + sales.forEach(sale => { salesIds.push(sale.id); params.push('?'); diff --git a/modules/ticket/back/methods/sale/specs/payment.spec.js b/modules/ticket/back/methods/sale/specs/payBack.spec.js similarity index 53% rename from modules/ticket/back/methods/sale/specs/payment.spec.js rename to modules/ticket/back/methods/sale/specs/payBack.spec.js index 9f0bcc98a..91ac8aceb 100644 --- a/modules/ticket/back/methods/sale/specs/payment.spec.js +++ b/modules/ticket/back/methods/sale/specs/payBack.spec.js @@ -3,15 +3,17 @@ const models = require('vn-loopback/server/server').models; describe('sale payBack()', () => { it('should create ticket with the selected lines changing the sign to the quantites', async() => { const tx = await models.Sale.beginTransaction({}); + const ctx = {req: {accessToken: {userId: 9}}}; + const ticketId = 11; const sales = [ {id: 7, ticketFk: 11}, {id: 8, ticketFk: 11} ]; + try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const response = await models.Sale.payBack(ctx, sales, ticketId, options); const [newTicketId] = await models.Sale.rawSql('SELECT MAX(t.id) id FROM vn.ticket t;', null, options); @@ -23,4 +25,30 @@ describe('sale payBack()', () => { throw e; } }); + + it('should throw error for not have privileges', async() => { + const tx = await models.Sale.beginTransaction({}); + const ctx = {req: {accessToken: {userId: 1}}}; + + const ticketId = 11; + const sales = [ + {id: 7, ticketFk: 11} + ]; + + let error; + + try { + const options = {transaction: tx}; + + await models.Sale.payBack(ctx, sales, ticketId, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error).toBeDefined(); + expect(error.message).toEqual(`You don't have privileges to create pay back`); + }); }); diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index fe1f5684d..5dc3c9428 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -492,7 +492,9 @@ + ng-click="$ctrl.createPayBack()" + vn-acl="claimManager, salesAssistant" + vn-acl-action="remove"> Pay Back \ No newline at end of file From 6890f7ddcbb8d6f7dac7a1fb77244ab20c319165 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 25 Jan 2022 15:09:29 +0100 Subject: [PATCH 2/4] refactor(ticket_sale): split e2e, change name backTest --- e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js | 4 +++- modules/ticket/back/methods/sale/payBack.js | 4 ++-- modules/ticket/back/methods/sale/specs/payBack.spec.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index f5f290c50..5078d5b91 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -206,11 +206,13 @@ describe('Ticket Edit sale path', () => { expect(message.text).toContain('Data saved!'); }); - it('should select the third sale and create a pay back', async() => { + it('should log in as salesAssistant and navigate to ticket sales', async() => { await page.loginAndModule('salesAssistant', 'ticket'); await page.accessToSearchResult('16'); await page.accessToSection('ticket.card.sale'); + }); + it('should select the third sale and create a pay back', async() => { await page.waitToClick(selectors.ticketSales.firstSaleCheckbox); await page.waitToClick(selectors.ticketSales.moreMenu); await page.waitToClick(selectors.ticketSales.moreMenuPayBack); diff --git a/modules/ticket/back/methods/sale/payBack.js b/modules/ticket/back/methods/sale/payBack.js index a7f04b1be..3bb056465 100644 --- a/modules/ticket/back/methods/sale/payBack.js +++ b/modules/ticket/back/methods/sale/payBack.js @@ -45,9 +45,9 @@ module.exports = Self => { const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager'); const isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant'); - const checkRoles = isClaimManager || isSalesAssistant; + const hasValidRole = isClaimManager || isSalesAssistant; - if (!checkRoles) + if (!hasValidRole) throw new UserError(`You don't have privileges to create pay back`); sales.forEach(sale => { diff --git a/modules/ticket/back/methods/sale/specs/payBack.spec.js b/modules/ticket/back/methods/sale/specs/payBack.spec.js index 91ac8aceb..ffcf96456 100644 --- a/modules/ticket/back/methods/sale/specs/payBack.spec.js +++ b/modules/ticket/back/methods/sale/specs/payBack.spec.js @@ -26,7 +26,7 @@ describe('sale payBack()', () => { } }); - it('should throw error for not have privileges', async() => { + it(`should throw an error if the user doesn't have privileges to create a pay back`, async() => { const tx = await models.Sale.beginTransaction({}); const ctx = {req: {accessToken: {userId: 1}}}; From 5a2677c7dea7b004e95a4b6b1f1ff8eabb1ca684 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 15 Feb 2022 13:21:13 +0100 Subject: [PATCH 3/4] Removed icons font color --- front/core/styles/icons/salixfont.css | 7 ------- 1 file changed, 7 deletions(-) diff --git a/front/core/styles/icons/salixfont.css b/front/core/styles/icons/salixfont.css index 24406837f..ff2eaa1f5 100644 --- a/front/core/styles/icons/salixfont.css +++ b/front/core/styles/icons/salixfont.css @@ -74,7 +74,6 @@ } .icon-bucket:before { content: "\e97a"; - color: #000; } .icon-buscaman:before { content: "\e93b"; @@ -84,32 +83,26 @@ } .icon-calc_volum .path1:before { content: "\e915"; - color: rgb(0, 0, 0); } .icon-calc_volum .path2:before { content: "\e916"; margin-left: -1em; - color: rgb(0, 0, 0); } .icon-calc_volum .path3:before { content: "\e917"; margin-left: -1em; - color: rgb(0, 0, 0); } .icon-calc_volum .path4:before { content: "\e918"; margin-left: -1em; - color: rgb(0, 0, 0); } .icon-calc_volum .path5:before { content: "\e919"; margin-left: -1em; - color: rgb(0, 0, 0); } .icon-calc_volum .path6:before { content: "\e91a"; margin-left: -1em; - color: rgb(255, 255, 255); } .icon-calendar:before { content: "\e93d"; From 3e33436bf6f98d24d8a0903ea42788de67df8357 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 16 Feb 2022 09:53:38 +0100 Subject: [PATCH 4/4] fix(report): Check ticket property first --- print/templates/reports/invoice/invoice.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js index bd85a812c..c5abfad7e 100755 --- a/print/templates/reports/invoice/invoice.js +++ b/print/templates/reports/invoice/invoice.js @@ -27,7 +27,8 @@ module.exports = { for (let sale of sales) { const ticket = map.get(sale.ticketFk); - ticket.sales.push(sale); + + if (ticket) ticket.sales.push(sale); } this.tickets = tickets;