-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
strongloop-community/loopback-acl-route#3
I finally found this repo. Basically copy the code from this file
https://github.com/strongloop/loopback/blob/9a33602458712afecedd25062f02bd8b5c4e01a5/test/role.test.js
Those two functions does not work. isInRole should be true
User.create({name: 'Raymond', email: '[email protected]', password: 'foobar'}, function(err, user) {
console.log('Created user ', user)
console.log('')
Role.create({"name": "userRole", "ownerId": ObjectID(user.id)}, function(err, role) {
console.log('Created role ', role)
console.log(err)
console.log('')
role.principals.create({principalType: RoleMapping.USER, principalId: user.id}, function(err, p) {
if (err) {
console.log(err)
throw err
}
console.log('Created principals')
console.log(p)
console.log('')
Role.isInRole('userRole', {principalType: RoleMapping.USER, principalId: user.id}, function(err, isInRole) {
console.log('Role.isInRole userRole')
console.log(isInRole)
console.log('')
})
})
})
})
Mongodb
db.user.find()
{
"_id" : ObjectId("56340e2d8e142283754e0b84"),
"password" : "$2a$10$9I6OAzexu4SCZo1GmbLO3eUaA6KJhhdd1hJAjbE3OVEM53V2LTQ/m",
"email" : "[email protected]",
"name" : "Raymond"
}
db.role.find()
{
"_id" : ObjectId("56340e2d8e142283754e0b85"),
"name" : "userRole",
"ownerId" : ObjectId("56340e2d8e142283754e0b84"),
"lastupdated" : ISODate("2015-10-31T00:41:17.257Z"),
"created" : ISODate("2015-10-31T00:41:17.257Z"),
"modified" : ISODate("2015-10-31T00:41:17.257Z")
}
db.RoleMapping.find({})
{
"_id" : ObjectId("56340e2d8e142283754e0b86"),
"principalType" : "USER",
"principalId" : "56340e2d8e142283754e0b84",
"roleId" : ObjectId("56340e2d8e142283754e0b85")
}
Need Help.
Many Thanks