2016-09-07 57 views
2

我目前正在评估loopback.io以开发新项目的API部分,并且在设置正确的ACL条目时遇到问题。访问控制列表问题loopback.io

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

下面是我的shows.json文件,我的用户模型名为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": {} 
} 

回答

1

这与ACL的无关。

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

如果你想你的工作电流owner AC1的,你需要创建usershow之间的关系,并在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" 
     }, 
....