fix(ticket): canEdit use aclFunc
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2022-10-04 15:02:00 +02:00
parent fe8ae164eb
commit 5f39249edb
1 changed files with 7 additions and 12 deletions

View File

@ -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;
};
};