42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
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) => {
|
|
const models = Self.app.models;
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
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'
|
|
)
|
|
);
|
|
|
|
const isAllowed = isAllEditable || isSomeEditable || state.alertLevel == 0;
|
|
return isAllowed;
|
|
};
|
|
};
|