update ticket.isEditable
gitea/salix/2070-ticket_tracking_update_permissions This commit looks good
Details
gitea/salix/2070-ticket_tracking_update_permissions This commit looks good
Details
This commit is contained in:
parent
d400e63aac
commit
bb09fc9746
|
@ -28,8 +28,7 @@ module.exports = Self => {
|
||||||
let isAdministrative = await models.Account.hasRole(userId, 'administrative');
|
let isAdministrative = await models.Account.hasRole(userId, 'administrative');
|
||||||
let state = await models.State.findById(stateId);
|
let state = await models.State.findById(stateId);
|
||||||
|
|
||||||
|
let salesPersonAllowed = (isSalesPerson && (state.code == 'PICKER_DESIGNED' || state.code == 'PRINTED'));
|
||||||
let salesPersonAllowed = (isSalesPerson && state.code == 'PICKER_DESIGNED');
|
|
||||||
|
|
||||||
let isAllowed = isProduction || isAdministrative || salesPersonAllowed || state.alertLevel == 0;
|
let isAllowed = isProduction || isAdministrative || salesPersonAllowed || state.alertLevel == 0;
|
||||||
return isAllowed;
|
return isAllowed;
|
||||||
|
|
|
@ -1,48 +1,61 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('state isEditable()', () => {
|
describe('state isEditable()', () => {
|
||||||
it('should return false if the given state is not editable by a specific role', async() => {
|
it('should return false if the state is not editable by a specific role', async() => {
|
||||||
const salesPersonRole = 18;
|
const salesPersonRole = 18;
|
||||||
const onDeliveryState = 13;
|
const onDeliveryState = 13;
|
||||||
let ctx = {req: {accessToken: {userId: salesPersonRole}}};
|
let ctx = {req: {accessToken: {userId: salesPersonRole}}};
|
||||||
let result = await app.models.State.isEditable(ctx, onDeliveryState);
|
let result = await app.models.State.isEditable(ctx, onDeliveryState);
|
||||||
|
|
||||||
expect(result).toBeFalsy();
|
expect(result).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if the given state is editable by a specific role', async() => {
|
it('should return true if the state is editable by a specific role', async() => {
|
||||||
const salesPersonRole = 18;
|
const salesPersonRole = 18;
|
||||||
const asignedState = 20;
|
const asignedState = 20;
|
||||||
let ctx = {req: {accessToken: {userId: salesPersonRole}}};
|
let ctx = {req: {accessToken: {userId: salesPersonRole}}};
|
||||||
let result = await app.models.State.isEditable(ctx, asignedState);
|
let result = await app.models.State.isEditable(ctx, asignedState);
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true again if the given state is editable by a specific role', async() => {
|
it('should return true again if the state is editable by a specific role', async() => {
|
||||||
const employeeRole = 1;
|
const employeeRole = 1;
|
||||||
const fixingState = 1;
|
const fixingState = 1;
|
||||||
let ctx = {req: {accessToken: {userId: employeeRole}}};
|
let ctx = {req: {accessToken: {userId: employeeRole}}};
|
||||||
let result = await app.models.State.isEditable(ctx, fixingState);
|
let result = await app.models.State.isEditable(ctx, fixingState);
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if the given state is not editable for the given role', async() => {
|
it('should return false if the state is not editable for the given role', async() => {
|
||||||
const employeeRole = 1;
|
const employeeRole = 1;
|
||||||
const asignedState = 20;
|
const asignedState = 20;
|
||||||
let ctx = {req: {accessToken: {userId: employeeRole}}};
|
let ctx = {req: {accessToken: {userId: employeeRole}}};
|
||||||
let result = await app.models.State.isEditable(ctx, asignedState);
|
let result = await app.models.State.isEditable(ctx, asignedState);
|
||||||
|
|
||||||
expect(result).toBeFalsy();
|
expect(result).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if the given state is editable for the given role', async() => {
|
it('should return true if the state is editable for the given role', async() => {
|
||||||
const productionRole = 49;
|
const productionRole = 49;
|
||||||
const checkedState = 13;
|
const onDeliveryState = 13;
|
||||||
let ctx = {req: {accessToken: {userId: productionRole}}};
|
let ctx = {req: {accessToken: {userId: productionRole}}};
|
||||||
let result = await app.models.State.isEditable(ctx, checkedState);
|
let result = await app.models.State.isEditable(ctx, onDeliveryState);
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if the ticket is editable, the role is salesPerson and the ticket state is printed', async() => {
|
||||||
|
const salesPersonRole = 18;
|
||||||
|
const printedState = 4;
|
||||||
|
const okState = 3;
|
||||||
|
const ctx = {req: {accessToken: {userId: salesPersonRole}}};
|
||||||
|
|
||||||
|
let canEditCurrent = await app.models.State.isEditable(ctx, printedState);
|
||||||
|
let canAsignNew = await app.models.State.isEditable(ctx, okState);
|
||||||
|
let result = canEditCurrent && canAsignNew;
|
||||||
|
|
||||||
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue