Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
920 stars 164 forks source link

Weird issue with role-assignement.. #364

Closed p-wieser closed 1 year ago

p-wieser commented 1 year ago

Hello, I am using alanning:roles 3.4.0 with Meteor 2.12. After having createRole() and addUsersToRoles(), i got following document in role-assignment:

  {
    _id: '9yJ5eBjJw7NjAQWkL',
    role: { _id: 'APP_ADMIN' },
    scope: null,
    user: { _id: 'L3aTjyqvErNMc2XDj' },
    inheritedRoles: [ 'APP_ADMIN' ]
  }

But as a matter of fact, when I getUsersInRole() for APP_ADMIN, I get an empty result set. This is rather logical, as code is (role_common.js, _getUsersInRoleCursor() function line 907)

selector = {
      'inheritedRoles._id': { $in: roles }
    }

As you can see, the selector addresses an _id field that my collection doesn't have.

As I have looked at the insertion code, I have found (line 490):

if (res.insertedId) {
      Meteor.roleAssignment.update({ _id: res.insertedId }, {
        $set: {
          inheritedRoles: [roleName, ...Roles._getInheritedRoleNames(role)].map(r => ({ _id: r }))
        }
      })
    }

I understand than inheritedRoles is an array, whose first element is the name of the first role, and others are objects { _id: name }.

Seens an inconsistency to me, but I am not sure at all to really understand..

So my main question is what did I have done wrong to get the result above (empty result set after having added a user to a role) ? How to fix that ?

Thanks in advance for you help. Regards

github-actions[bot] commented 1 year ago

Thank you for submitting this issue!

We, the Members of Meteor Community Packages take every issue seriously. Our goal is to provide long-term lifecycles for packages and keep up with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem.

However, we contribute to these packages mostly in our free time. Therefore, we can't guarantee your issues to be solved within certain time.

If you think this issue is trivial to solve, don't hesitate to submit a pull request, too! We will accompany you in the process with reviews and hints on how to get development set up.

Please also consider sponsoring the maintainers of the package. If you don't know who is currently maintaining this package, just leave a comment and we'll let you know

p-wieser commented 1 year ago

Oop's. It happens this was a bug of my code :( Fixed now. Sorry for the noise. And thanks for your work.