2020-06-16 05:47:46 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('isEditable', {
|
2023-02-07 14:40:03 +00:00
|
|
|
description: 'Check if an state is editable',
|
2020-06-16 05:47:46 +00:00
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'id',
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
2023-02-07 14:40:03 +00:00
|
|
|
description: 'the st id',
|
2020-06-16 05:47:46 +00:00
|
|
|
http: {source: 'path'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'boolean',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/isEditable`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-05 10:00:49 +00:00
|
|
|
Self.isEditable = async(ctx, id, options) => {
|
2020-06-16 05:47:46 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
2023-02-07 14:40:03 +00:00
|
|
|
const models = Self.app.models;
|
2021-07-05 10:00:49 +00:00
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
2023-02-07 14:40:03 +00:00
|
|
|
|
|
|
|
const state = await models.ClaimState.findById(id, {
|
|
|
|
include: {
|
|
|
|
relation: 'writeRole'
|
|
|
|
}
|
|
|
|
}, myOptions);
|
|
|
|
const roleWithGrants = state && state.writeRole().name;
|
|
|
|
return await models.Account.hasRole(userId, roleWithGrants, myOptions);
|
2020-06-16 05:47:46 +00:00
|
|
|
};
|
|
|
|
};
|