2016-09-07 9 views
2

現在、新しいプロジェクトのAPI部分を開発するためにloopback.ioを評価していますが、正しいACLエントリの設定に問題があります。loopback.ioのACLトラブル

私が達成したいのは認証トークンです.GETエンドポイントはユーザーが所有するオブジェクトのみを返すべきです。たとえば、/ show?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": {} 
} 

答えて

1

これはACLとは関係ありません。

メソッドのビジネスロジックを変更したいとします。したがって、現在のユーザーが所有する番組を取得するための新しい方法を作成することをお勧めします。

あなたが現在owner ACLを操作したい場合は、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" 
     }, 
....