diff --git a/modules/ticket/back/methods/sale/canEdit.js b/modules/ticket/back/methods/sale/canEdit.js index f359b19e4..94c2fc19a 100644 --- a/modules/ticket/back/methods/sale/canEdit.js +++ b/modules/ticket/back/methods/sale/canEdit.js @@ -14,23 +14,22 @@ module.exports = Self => { root: true }, http: { - path: `/isEditable`, + path: `/canEdit`, verb: 'get' } }); Self.canEdit = async(ctx, sales, options) => { const models = Self.app.models; - const userId = ctx.req.accessToken.userId; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - /* const firstSale = await models.Sale.findById(sales[0], null, myOptions); + const firstSale = await models.Sale.findById(sales[0], null, myOptions); const isTicketEditable = await models.Ticket.isEditable(ctx, firstSale.ticketFk, myOptions); if (!isTicketEditable) - throw new UserError(`The sales of this ticket can't be modified`);*/ + throw new UserError(`The sales of this ticket can't be modified`); const saleTracking = await models.SaleTracking.find({where: {saleFk: {inq: sales}}}, myOptions); const hasSaleTracking = saleTracking.length; @@ -38,15 +37,11 @@ module.exports = Self => { const saleCloned = await models.SaleCloned.find({where: {saleClonedFk: {inq: sales}}}, myOptions); const hasSaleCloned = saleCloned.length; - /* const isProductionRole = await models.Account.hasRole(userId, 'production', myOptions); - const canEdit = (isProductionRole || !hasSaleTracking);// && (isRole || !hasSaleCloned); + const canEditTracked = await models.Account.aclFunc(ctx, 'editTracked'); + const canEditCloned = await models.Account.aclFunc(ctx, 'editCloned'); - const isRole = await models.Account.hasRole(userId, 'developer', myOptions);*/ - const editTracked = await models.Account.aclFunc(ctx, 'editTracked'); - const editCloned = await models.Account.aclFunc(ctx, 'editCloned'); - console.log(editTracked); - const canEdit = (editTracked || !hasSaleTracking) && (editCloned || !hasSaleCloned); + const canEdit = (canEditTracked || !hasSaleTracking) && (canEditCloned || !hasSaleCloned); - return canEdit;// && isTicketEditable; + return canEdit; }; };