使用Project.find()或GET /projects,我只想获得当前用户的项目。应该在哪里进行过滤?我尝试过在project.json中使用acls:
"accessType": "*",
"principalType": "ROLE",
"principalId": "teamMember",
"permission": "ALLOW"和一个注册的解析器。但我只能将其用于findById()或get / projects /:id,而不能用于列出所有项目。
我也尝试过在project.js中作为观察者:
Project.observe('access', function(ctx, next){
ctx.query.where.memberId = 1;
next();
});等等。
这应该怎么做呢?我还在这里研究了一个类似案例的回送教程:http://docs.strongloop.com/display/public/LB/Tutorial%3A+access+control
虽然这不是我想要做的,但我被卡住了:)
发布于 2015-07-08 22:57:39
您可以在get方法中使用where filter来实现您想要的结果。在你的项目模型中,你可能有userId。您需要做的是在请求中添加带有userId的"where“过滤器
/projects?filterwhere=1
,或者如果你想使用node API,你可以这样做:
Project.find({
where: {userId: 1}
},
function(err, projects){
//do something with projects
});更新:如果你想修改读操作上的查询,那么你需要使用操作钩子。你走在了正确的道路上。
Project.observe('access', function(ctx, next){
ctx.query = {"where": {userId: 1}}; //define your query as needed
next();
}); https://stackoverflow.com/questions/31291992
复制相似问题