我们现在为CMS用户(内容创建者)提供了字段级权限,但是是否有办法为API添加字段级权限?将集合类型或组件中的某些字段限制为某些最终用户角色?
我想实现这个:
const Article = {
preview: 'Hello this is a .....", // Public ',
body: 'Only paid users of a certain role can see this text', // Authenticated with Role: Subscriber
};
例如:角色为订阅者的用户,将看到以下内容:
const Article = {
preview: 'Hello this is a .....", // Public ',
body: 'Only paid users of a certain role can see this text', // Authenticated with Role: Subscriber
};
没有这个角色的人看这个:
const Article = {
preview: 'Hello this is a .....", // Public ',
};
我相信我为我的内容调查(在控制器中)实现了类似的东西,我不希望未经身份验证的人看到某些字段(特别是关系),这就是我删除这些字段的原因:)
如果代码是有用的,或者如果你需要更多的信息,请告诉我。
祝你好运!
async findOne(ctx) {
const { id } = ctx.params;
const { user } = ctx.state;
(...)
const entity = await strapi.services.survey.findOne({ id });
let survey = sanitizeEntity(entity, { model: strapi.models.survey })
if ((user == null) || (user.id != survey.users_permissions_user.id)) {
delete survey.users_permissions_user;
delete survey.interviewees;
}
return survey
},
};