Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role.isInRole && ACL.isMappedToRole do not work #1790

Closed
mike-aungsan opened this issue Oct 31, 2015 · 1 comment
Closed

Role.isInRole && ACL.isMappedToRole do not work #1790

mike-aungsan opened this issue Oct 31, 2015 · 1 comment
Assignees

Comments

@mike-aungsan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants