Skip to content

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

Description

@mike-aungsan

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: 'x@y.com', 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" : "x@y.com",
"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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions