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

Proper way to remove user from group? #194

Closed phocks closed 8 years ago

phocks commented 8 years ago

Hi there, I'm just wondering is there a Roles.deleteUsersFromRoles( function to delete a user from the admin role. I tried using setUserRoles to [] but then when I tried adding a user to admin again + a group it gave me an error "Error: Roles error: Can't mix grouped and non-grouped roles for same user".

mitar commented 8 years ago

You have to decide if you are using groups or not. Can you share more of the code you are using?

phocks commented 8 years ago

I'm just running tests from meteor shell

> Roles.addUsersToRoles("jNX4BenrzyEgsMqTY", "admin");
> Roles.setUserRoles("jNX4BenrzyEgsMqTY", []);
> Roles.addUsersToRoles("jNX4BenrzyEgsMqTY", "admin", "default-group");
Error: Roles error: Can't mix grouped and non-grouped roles for same user

I think I've worked out what's happening anyway. When I added my user to the admin role with no group it created the group "admin" doc in db.groups. I'm guessing to use the "admin" role along with groups I would now have to go and delete the "admin" doc from the database and start again.

mitar commented 8 years ago

You are mixing groups and no groups. In the first command you have run it without groups. So now you are stuck with no groups.

phocks commented 8 years ago

Ahh yes I ran into that. Fixed it by deleting the roles: [] key from my user. Thanks for your help. It might not be too difficult to simply force using a "default-group' when no group is specified. I might fork and see if I can make a patch if I have time down the track.

Cheers.

mitar commented 8 years ago

This is fixed in the v2.0 branch, BTW. There you do not have such issues anymore.