Handle ticket without old state #384

Merged
bernat merged 1 commits from 2472-ticket_tracking_fix into dev 2020-09-22 06:37:56 +00:00
2 changed files with 6 additions and 4 deletions

View File

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

2
package-lock.json generated
View File

@ -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": {