From a8c6c57b7e158d2a7b9abd05ab10b41ad21d81e9 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 26 Sep 2019 12:07:40 +0200 Subject: [PATCH] #1719 claim.detail final amends and tests --- modules/ticket/back/methods/ticket/isEditable.js | 7 +++++-- .../ticket/back/methods/ticket/specs/isEditable.spec.js | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/isEditable.js b/modules/ticket/back/methods/ticket/isEditable.js index 06fb2fed2..3ebf15bf0 100644 --- a/modules/ticket/back/methods/ticket/isEditable.js +++ b/modules/ticket/back/methods/ticket/isEditable.js @@ -26,7 +26,10 @@ module.exports = Self => { where: {ticketFk: id} }); - let isProductionBoss = await Self.app.models.Account.hasRole(userId, 'salesAssistant'); + const isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant'); + const isProductionBoss = await Self.app.models.Account.hasRole(userId, 'productionBoss'); + const isValidRole = isSalesAssistant || isProductionBoss; + let alertLevel = state ? state.alertLevel : null; let ticket = await Self.app.models.Ticket.findById(id, { fields: ['isDeleted', 'clientFk', 'refFk'], @@ -45,7 +48,7 @@ module.exports = Self => { const isNormalClient = ticket && ticket.client().type().code == 'normal'; const isInvoiced = ticket && ticket.refFk; - if (!ticket || isInvoiced || isDeleted || (isOnDelivery && isNormalClient && !isProductionBoss)) + if (!ticket || isInvoiced || isDeleted || (isOnDelivery && isNormalClient && !isValidRole)) return false; return true; diff --git a/modules/ticket/back/methods/ticket/specs/isEditable.spec.js b/modules/ticket/back/methods/ticket/specs/isEditable.spec.js index b64981d02..a40128954 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditable.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditable.spec.js @@ -29,6 +29,13 @@ describe('ticket isEditable()', () => { expect(result).toEqual(true); }); + it('should be able to edit a deleted or invoiced ticket if the role is salesAssistant', async() => { + let ctx = {req: {accessToken: {userId: 21}}}; + let result = await app.models.Ticket.isEditable(ctx, 8); + + expect(result).toEqual(true); + }); + it('should be able to edit a deleted or invoiced ticket if the role is productionBoss', async() => { let ctx = {req: {accessToken: {userId: 50}}}; let result = await app.models.Ticket.isEditable(ctx, 8);