#1719 claim.detail final amends and tests
gitea/salix/1719-claim-detail This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2019-09-26 12:07:40 +02:00
parent e57210fdfc
commit a8c6c57b7e
2 changed files with 12 additions and 2 deletions

View File

@ -26,7 +26,10 @@ module.exports = Self => {
where: {ticketFk: id} where: {ticketFk: id}
}); });
let isProductionBoss = await Self.app.models.Account.hasRole(userId, 'salesAssistant'); const isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant');
const isProductionBoss = await Self.app.models.Account.hasRole(userId, 'productionBoss');
const isValidRole = isSalesAssistant || isProductionBoss;
let alertLevel = state ? state.alertLevel : null; let alertLevel = state ? state.alertLevel : null;
let ticket = await Self.app.models.Ticket.findById(id, { let ticket = await Self.app.models.Ticket.findById(id, {
fields: ['isDeleted', 'clientFk', 'refFk'], fields: ['isDeleted', 'clientFk', 'refFk'],
@ -45,7 +48,7 @@ module.exports = Self => {
const isNormalClient = ticket && ticket.client().type().code == 'normal'; const isNormalClient = ticket && ticket.client().type().code == 'normal';
const isInvoiced = ticket && ticket.refFk; const isInvoiced = ticket && ticket.refFk;
if (!ticket || isInvoiced || isDeleted || (isOnDelivery && isNormalClient && !isProductionBoss)) if (!ticket || isInvoiced || isDeleted || (isOnDelivery && isNormalClient && !isValidRole))
return false; return false;
return true; return true;

View File

@ -29,6 +29,13 @@ describe('ticket isEditable()', () => {
expect(result).toEqual(true); expect(result).toEqual(true);
}); });
it('should be able to edit a deleted or invoiced ticket if the role is salesAssistant', async() => {
let ctx = {req: {accessToken: {userId: 21}}};
let result = await app.models.Ticket.isEditable(ctx, 8);
expect(result).toEqual(true);
});
it('should be able to edit a deleted or invoiced ticket if the role is productionBoss', async() => { it('should be able to edit a deleted or invoiced ticket if the role is productionBoss', async() => {
let ctx = {req: {accessToken: {userId: 50}}}; let ctx = {req: {accessToken: {userId: 50}}};
let result = await app.models.Ticket.isEditable(ctx, 8); let result = await app.models.Ticket.isEditable(ctx, 8);