diff --git a/client/ticket/src/tracking/edit/index.html b/client/ticket/src/tracking/edit/index.html
index a72633332..ae116da03 100644
--- a/client/ticket/src/tracking/edit/index.html
+++ b/client/ticket/src/tracking/edit/index.html
@@ -1,4 +1,4 @@
-
+
{
- Self.remoteMethod('changeState', {
+ Self.remoteMethodCtx('changeState', {
description: 'Change the state of a ticket',
accessType: 'WRITE',
accepts: [{
@@ -21,11 +21,22 @@ module.exports = Self => {
}
});
- Self.changeState = async params => {
+ Self.changeState = async(ctx, params) => {
+ let models = Self.app.models;
+ let isProduction;
let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
- if (isEditable)
- return await Self.app.models.TicketTracking.create(params);
- throw new UserError(`You don't have enough privileges to change the state of this ticket`);
+ if (ctx.req.accessToken) {
+ let token = ctx.req.accessToken;
+ let currentUserId = token && token.userId;
+ isProduction = await models.Account.hasRole(currentUserId, 'Production');
+ let worker = await models.Worker.findOne({where: {userFk: currentUserId}});
+ params.workerFk = worker.id;
+ }
+
+ if (!isEditable && !isProduction)
+ throw new UserError(`You don't have enough privileges to change the state of this ticket`);
+
+ return await Self.app.models.TicketTracking.create(params);
};
};
diff --git a/services/ticket/common/models/ticket-tracking.js b/services/ticket/common/models/ticket-tracking.js
index 45acf7f90..2ebef8a9a 100644
--- a/services/ticket/common/models/ticket-tracking.js
+++ b/services/ticket/common/models/ticket-tracking.js
@@ -2,13 +2,4 @@ module.exports = function(Self) {
require('../methods/ticket-tracking/changeState')(Self);
Self.validatesPresenceOf('stateFk', {message: 'State cannot be blank'});
-
- Self.observe('before save', async function(ctx) {
- let models = Self.app.models;
- let token = ctx.options.accessToken;
- let currentUserId = token && token.userId;
-
- let worker = await models.Worker.findOne({where: {userFk: currentUserId}});
- ctx.instance.workerFk = worker.id;
- });
};