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 root: true
}, },
http: { http: {
path: `/isEditable`, path: `/canEdit`,
verb: 'get' verb: 'get'
} }
}); });
Self.canEdit = async(ctx, sales, options) => { Self.canEdit = async(ctx, sales, options) => {
const models = Self.app.models; const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); 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); const isTicketEditable = await models.Ticket.isEditable(ctx, firstSale.ticketFk, myOptions);
if (!isTicketEditable) 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 saleTracking = await models.SaleTracking.find({where: {saleFk: {inq: sales}}}, myOptions);
const hasSaleTracking = saleTracking.length; const hasSaleTracking = saleTracking.length;
@ -38,15 +37,11 @@ module.exports = Self => {
const saleCloned = await models.SaleCloned.find({where: {saleClonedFk: {inq: sales}}}, myOptions); const saleCloned = await models.SaleCloned.find({where: {saleClonedFk: {inq: sales}}}, myOptions);
const hasSaleCloned = saleCloned.length; const hasSaleCloned = saleCloned.length;
/* const isProductionRole = await models.Account.hasRole(userId, 'production', myOptions); const canEditTracked = await models.Account.aclFunc(ctx, 'editTracked');
const canEdit = (isProductionRole || !hasSaleTracking);// && (isRole || !hasSaleCloned); const canEditCloned = await models.Account.aclFunc(ctx, 'editCloned');
const isRole = await models.Account.hasRole(userId, 'developer', myOptions);*/ const canEdit = (canEditTracked || !hasSaleTracking) && (canEditCloned || !hasSaleCloned);
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);
return canEdit;// && isTicketEditable; return canEdit;
}; };
}; };