From 89667a18c90155eb7427adfd6932ea6a42c089c5 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 22 Sep 2020 07:50:30 +0200 Subject: [PATCH] Handle ticket without old state --- .../ticket/back/methods/ticket-tracking/changeState.js | 8 +++++--- package-lock.json | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket-tracking/changeState.js b/modules/ticket/back/methods/ticket-tracking/changeState.js index e28413b24..f7baeecfd 100644 --- a/modules/ticket/back/methods/ticket-tracking/changeState.js +++ b/modules/ticket/back/methods/ticket-tracking/changeState.js @@ -40,15 +40,17 @@ module.exports = Self => { params.workerFk = worker.id; } - let ticket = await models.TicketState.findById( + let ticketState = await models.TicketState.findById( params.ticketFk, {fields: ['stateFk']} ); - let oldStateAllowed = await models.State.isEditable(ctx, ticket.stateFk); + let oldStateAllowed; + if (ticketState) + oldStateAllowed = await models.State.isEditable(ctx, ticketState.stateFk); let newStateAllowed = await models.State.isEditable(ctx, params.stateFk); - let isAllowed = oldStateAllowed && newStateAllowed; + let isAllowed = (!ticketState || oldStateAllowed == true) && newStateAllowed == true; if (!isAllowed) throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED'); diff --git a/package-lock.json b/package-lock.json index 601f6681b..b5a27cb21 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22928,7 +22928,7 @@ }, "sha.js": { "version": "2.4.11", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "dev": true, "requires": { -- 2.40.1