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
921 stars 168 forks source link

getGroupsForUser - [role] being treated as mutually exclusive #170

Closed romant closed 8 years ago

romant commented 8 years ago

documentation relates :

[role] String optional Optional name of roles to restrict groups to.

Yet trying it with a user that belongs to a group; upon which I then query Roles.getGroupsForUser('mCE2dx2n964MbLjPi', ['oger','minion']) results in an empty []

Whilst the same query for a single role

Roles.getGroupsForUser('mCE2dx2n964MbLjPi', 'minion')

Returns the expected array of Groups.

I notice that the code actually does iterate over all the groupRoles - but in this case - actually returns an empty array.

Any pointers on debugging?

Many thanks.

miri-am commented 8 years ago

Looks like roleneeds to be a String: http://alanning.github.io/meteor-roles/files/roles_roles_common.js.html#l485 The code iterates over user.roles but not role.

alanning commented 8 years ago

Yes, currently that function requires a single string. I think you may be confused by the jsdoc syntax; in this case brackets around the parameter name indicate that the parameter is optional. If the parameter accepts a String or an Array, the format would be:

* @param {Array|String} role Name of role/permission...

romant commented 8 years ago

Thank you @alanning. That's helpful.

Don't suppose any plans underway to add array of strings support ? Or is focus on v.2 ? In which case - what's the plan for behaviour there for a multiple role check?

mitar commented 8 years ago

This is a duplicate of #140 for which there was a pull request #148.

In v2.0 this is already implemented.

mitar commented 8 years ago

See also tests in c07767d6e0c792e774a156788ee5fad52163c2d3 to see if that covers your use case.

romant commented 8 years ago

Thank you @mitar. What's the eta for v2.0 ?

mitar commented 8 years ago

See #165 for the discussion on the topic. You can also try it out in v2.0 branch. I think most things are ready, but it needs more testing by users so that we see if everything works as expected.