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);