2016-03-25 1 views
-1

Ich habe ein Benutzermodell erstellt, das vom Basisbenutzermodell erweitert wurde, und eine Beziehung zu einem anderen persistenten Modell hinzugefügt. Als ich versuchte, den Zugriff auf die über den Explorer relationmethods es BerechtigungsfehlerSo ändern Sie das Standardbenutzermodell acl, wenn Sie eine Beziehung mit einem anderen persistenten Modell im Loopback erstellen?

Meine usermodel Struktur (json)

{ 
    "name": "teamuser", 
    "base": "User", 
    "idInjection": true, 
    "options": { 
    "validateUpsert": true 
    }, 
    "properties": { 
    "empid": { 
     "type": "number", 
     "required": true 
    }, 
    "designation": { 
     "type": "string" 
    } 
    }, 
    "validations": [], 
"relations": { 
    "tasks": { 
     "type": "hasMany", 
     "model": "task", 
     "foreignKey": "userid" 
    } 
    }, 
"acls": [], 
    "methods": {} 
} 

MyTask Modellstruktur (json)

{ 
    "name": "task", 
    "base": "PersistedModel", 
    "idInjection": true, 
    "options": { 
    "validateUpsert": true 
    }, 
    "properties": { 
    "title": { 
     "type": "string", 
     "required": true 
    }, 
    "desc": { 
     "type": "string" 
    }, 
    "startdate": { 
     "type": "date", 
     "required": true 
    }, 
    "enddate": { 
     "type": "date", 
     "required": true 
    }, 
    "status": { 
     "type": "string", 
     "required": true 
    } 
    }, 
    "validations": [], 
"relations": { 
    "teamuser": { 
     "type": "belongsTo", 
     "model": "teamuser", 
     "foreignKey": "userid" 
    }, 
    "project": { 
     "type": "belongsTo", 
     "model": "project", 
     "foreignKey": "" 
    } 
    }, 
"acls": [], 
    "methods": {} 
} 

Wenn ich s geben versuchen, dies zu schlagen unten Methode in erforschten bekomme ich den Fehler

http://0.0.0.0:3000/api/teamusers/5/tasks?access_token=AQVBwaoo1g0msk2eRvyAqbybCvKmswhHfLh1SeNYrzmsvn1gmCou5EaDBTpaiA2M

{ 
    "error": { 
    "name": "Error", 
    "status": 401, 
    "message": "Authorization Required", 
    "statusCode": 401, 
    "code": "AUTHORIZATION_REQUIRED", 
    "stack": "Error: Authorization Required\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/lib/application.js:376:21\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/lib/model.js:313:7\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/common/models/acl.js:465:23\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/node_modules/async/lib/async.js:251:17\n at done (/Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/node_modules/async/lib/async.js:132:19)\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/node_modules/async/lib/async.js:32:16\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/node_modules/async/lib/async.js:248:21\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/node_modules/async/lib/async.js:572:34\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/common/models/acl.js:447:17\n at /Users/mohamediqbalsaleem/Documents/easasoft/Testcb/node_modules/loopback/common/models/role.js:268:21" 


    } 
} 

Antwort

0

Dies ist wahrscheinlich auf das Standard-ACL-Verhalten für Beziehungen in Loopback zurückzuführen. Aus der Dokumentation:

Standardmäßig haben alle verwandten Modellmethoden eine Einstellung für DENY ALL ACL. Sie müssen explizit Zugriff gewähren. ACLs erben nicht vom Zielmodell des Ziels . Selbst wenn beispielsweise die Standard- ACL des Buchmodells für GET/books die Berechtigung ALLOW $ hat, wird die Route GET /user/{id}/books default immer DENY ALL sein.

https://docs.strongloop.com/display/public/LB/Accessing+related+models

Sie müssen explizit die ACL/teamusers/{id}/Aufgaben festgelegt.

0

Im Modell "Teamuser" ist Ihr Basismodell "Benutzer". Es erbt seine Funktion. Sie können es durch eine einfache Art und Weise außer Kraft setzen -

einfach außer Kraft setzen Eltern "ACL" von Ihnen "ACL" -

{ 
 
    "name": "teamuser", 
 
    "base": "User", 
 
    "idInjection": true, 
 
    "options": { 
 
    "validateUpsert": true 
 
    }, 
 
    "properties": { 
 
    "empid": { 
 
     "type": "number", 
 
     "required": true 
 
    }, 
 
    "designation": { 
 
     "type": "string" 
 
    } 
 
    }, 
 
    "validations": [], 
 
"relations": { 
 
    "tasks": { 
 
     "type": "hasMany", 
 
     "model": "task", 
 
     "foreignKey": "userid" 
 
    } 
 
    }, 
 
"acls": [ 
 
    { 
 
     "principalType": "ROLE", 
 
     "principalId": "$everyone", 
 
     "accessType": "READ", 
 
     "permission": "ALLOW" 
 
    } 
 
], 
 
    "methods": {} 
 
}

Verwandte Themen