loopback.io 的 ACL 问题

ACL troubles with loopback.io

我目前正在评估 loopback.io 以开发新项目的 API 部分,但我在设置正确的 ACL 条目方面遇到了问题。

我希望完成的是给定一个身份验证令牌,GET 端点应该只 return 用户拥有的对象。例如,对 /Shows?access_token=xxxxxx 的请求应该 return 只有用户拥有的对象。

下面是我的 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,您需要在 usershow 之间创建一个关系,并在 [=13] 中设置 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"
        },
....