salix/modules/ticket/back/methods/state/isEditable.js

42 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2019-08-12 11:26:44 +00:00
module.exports = Self => {
Self.remoteMethodCtx('isEditable', {
description: 'Check if the ticket state is editable',
accessType: 'READ',
accepts: [{
arg: 'stateId',
type: 'number',
required: true,
http: {source: 'path'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:stateId/isEditable`,
verb: 'get'
}
});
Self.isEditable = async(ctx, stateId, options) => {
2019-08-12 11:26:44 +00:00
const models = Self.app.models;
const myOptions = {};
2019-08-12 11:26:44 +00:00
if (typeof options == 'object')
Object.assign(myOptions, options);
2019-08-12 11:26:44 +00:00
const isAllEditable = await models.ACL.checkAccessAcl(ctx, 'State', 'isAllEditable', 'READ');
const state = await models.State.findById(stateId, null, myOptions);
const isSomeEditable = (
await models.ACL.checkAccessAcl(ctx, 'State', 'isSomeEditable', 'READ')
&& (
state.code == 'PICKER_DESIGNED' || state.code == 'PRINTED'
)
);
2019-08-12 11:26:44 +00:00
const isAllowed = isAllEditable || isSomeEditable || state.alertLevel == 0;
2019-08-12 11:26:44 +00:00
return isAllowed;
};
};