我目前正在评估用于开发新项目的 API 部分的 Loopback.io,但在设置正确的 ACL 条目时遇到问题。
我希望完成的是给定一个身份验证 token ,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": {}
}
最佳答案
与 ACL 无关。
您想要更改该方法的业务逻辑。因此,最佳实践是创建一种新方法来获取当前用户拥有的节目。
如果您想使用当前owner
ACL,您需要在user
和show
之间创建关系,并设置
。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"
},
....
关于node.js - Loopback.io 的 ACL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39372950/