ACL遇到loopback.io问题

我目前正在评估loopback.io来开发新项目的API部分,而且我在设置正确的ACL条目时遇到了问题。

我希望完成的是一个授权令牌,GET端点只应该返回用户拥有的对象。 例如,对/ Shows?access_token = xxxxxx的请求应只返回用户拥有的对象。

下面是我的shows.json文件,我的User模型被命名为Podcaster。 任何帮助,将不胜感激。

{ "name": "Show", "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "properties": { "title": { "type": "string", "required": true }, "description": { "type": "string" } }, "validations": [], "relations": { "episodes": { "type": "hasMany", "model": "Episode", "foreignKey": "" }, "podcaster": { "type": "belongsTo", "model": "Podcaster", "foreignKey": "" } }, "acls": [ { "accessType": "WRITE", "principalType": "ROLE", "principalId": "$authenticated", "permission": "ALLOW", "property": "create" }, { "accessType": "*", "principalType": "ROLE", "principalId": "$owner", "permission": "ALLOW" }, { "accessType": "*", "principalType": "ROLE", "principalId": "$everyone", "permission": "DENY" } ], "methods": {} } 

这与ACL的无关。

你想改变方法的业务逻辑。 所以最好的做法是创build一个获取当前用户拥有的节目的新方法。

如果您想要使用当前owner AC1,则需要在usershow之间创build关系,并在show模型中设置ownerId

  { "name": "Show", "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "properties": { "title": { "type": "string", "required": true }, "description": { "type": "string" }, "description": { "type": "string" } "ownerId": { "type": "object" } }, "validations": [], "relations": { "owner": { "type": "belongsTo", "model": "user", "foreignKey": "ownerId" }, ....