5929-editTicketPrice #1688
|
@ -0,0 +1,2 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`)
|
||||
VALUES ('Ticket','*','*','ALLOW','ROLE','buyer');
|
|
@ -307,5 +307,7 @@
|
|||
"Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}",
|
||||
"The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias",
|
||||
"You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado",
|
||||
"This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado"
|
||||
}
|
||||
"This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado",
|
||||
"You don't have enough privileges.": "You don't have enough privileges.",
|
||||
"This ticket is locked.": "This ticket is locked."
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('isEditable', {
|
||||
description: 'Check if a ticket is editable',
|
||||
|
@ -31,7 +33,7 @@ module.exports = Self => {
|
|||
}, myOptions);
|
||||
|
||||
const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*');
|
||||
|
||||
const canEditWeeklyTicket = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'buyer', 'WRITE');
|
||||
const alertLevel = state ? state.alertLevel : null;
|
||||
const ticket = await models.Ticket.findById(id, {
|
||||
fields: ['clientFk'],
|
||||
|
@ -48,13 +50,26 @@ module.exports = Self => {
|
|||
const isLocked = await models.Ticket.isLocked(id, myOptions);
|
||||
const isWeekly = await models.TicketWeekly.findOne({where: {ticketFk: id}}, myOptions);
|
||||
|
||||
console.log('isRoleAdvanced', isRoleAdvanced);
|
||||
console.log('canEditWeeklyTicket', canEditWeeklyTicket);
|
||||
console.log('ticket', ticket);
|
||||
console.log('isLocked', isLocked);
|
||||
console.log('isWeekly', isWeekly);
|
||||
const alertLevelGreaterThanZero = (alertLevel && alertLevel > 0);
|
||||
const isNormalClient = ticket && ticket.client().type().code == 'normal';
|
||||
const isEditable = !(alertLevelGreaterThanZero && isNormalClient);
|
||||
if (!ticket)
|
||||
throw new UserError(`The ticket doesn't exist.`);
|
||||
|
||||
if (ticket && (isEditable || isRoleAdvanced) && !isLocked && !isWeekly)
|
||||
return true;
|
||||
if (!isEditable && !isRoleAdvanced)
|
||||
throw new UserError(`This ticket is not editable.`);
|
||||
|
||||
return false;
|
||||
if (isLocked)
|
||||
throw new UserError(`This ticket is locked.`);
|
||||
|
||||
if (isWeekly && !canEditWeeklyTicket)
|
||||
throw new UserError(`You don't have enough privileges.`);
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue