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

Roles.createRole simply not working. #107

Closed vacarsu closed 9 years ago

vacarsu commented 9 years ago

Hi, I'm trying to setup the roles. Currently I have one role named 'admin', however when I try to make any other role it simply doesn't work. I get no errors when trying to create them from the client, but when I try to create the from a server startup I get the following error, MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: meteor.roles.$userId_1 dup key: { : null }.

alanning commented 9 years ago

Hi @vacarsu, looks like you added an index to the "roles" collection that is preventing the insertion of duplicate user ids. Does that sound feasible? This package only adds one index, an index on the "name" field of the "roles" collection.

vacarsu commented 9 years ago

I assumed this as well, I used the meteor mongo CL to remove indexes and I still have the problem. If it helps I'm using Collection2.

EDIT: After removing indexes it appears I can set a user role now, however creating a role doesn't seem to work. the role appears to be created however, if I set a user to a role that does not exist. I can create them from the startup file, though.

alanning commented 9 years ago

Can you post an example app to a public repo for me to look at? Otherwise, I'd suggest stripping it down to the minimal app that works and then adding pieces back until it stops working again. Then you'll know which piece is causing the trouble.

One other issue I've heard before is that packages that modify internal Meteor collection objects mess things up somehow and that making sure the roles package comes before the collection package in the .meteor/packages file may help.

vacarsu commented 9 years ago

I'm using angular-meteor, could this be the problem? I'll put up an example project shortly, I've got it kind of working as I can create the roles from the startup, and set users to roles now. but I can't seem to add roles from the front end.

Basically, how I currently have this set up - I have a meteor method which is just the Roles.createRole() method, them I'm using the $meteor.call service to call that method and create the role. I'm doing the same thing for role deletion too.

vacarsu commented 9 years ago

Here is the repo. https://github.com/vacarsu/roles-example

vacarsu commented 9 years ago

I'm going to close this, as the main issue to this has been solved.

alanning commented 9 years ago

The issue is that the Roles.createRole call is always being passed null.

Try changing the addRole Meteor method to this:

  addRole: function (role) {
    console.log("[addRole]", role)
  Roles.createRole(role);
  return 'success';
  },

Also, this is my first look at angular but man that seems a bit complicated. Have you tried just using straight Blaze? You can still use Polymer so the styling wouldn't have to change.

On Tue, Jun 2, 2015 at 10:18 PM, vacarsu notifications@github.com wrote:

Closed #107 https://github.com/alanning/meteor-roles/issues/107.

— Reply to this email directly or view it on GitHub https://github.com/alanning/meteor-roles/issues/107#event-320684571.

vacarsu commented 9 years ago

That worked! And yes angular looks pretty complicated but once you learn it it's pretty powerful. I will definitely look into blaze and polymer. Thanks for your help!

thomasmery commented 8 years ago

Hi there,

just a note to say I had the same pb

all I did was:

indexes on the roles collection showed _id and name had to remove index from name

seems to be ok now

any insight as to why this is happening?

many thnks!

alanning commented 8 years ago

@thomasmery, thanks for reporting this. In your case, you are using the v2.0 branch of roles which uses a different database schema structure. Version 1 has an index on the 'name' field as I mentioned above. In version 2, there is no 'name' field so MongoDB is interpreting the lack of a field as "undefined" and throwing the duplicate error due to there being more than one "undefined" name value.

So anyone using the v2.0 branch with a database that already has data in it from v1 will need to remove the index on name as you found.

I'll create a new v2 issue for this so we can track it and better help people make the transition.

mitar commented 8 years ago

This is then duplicate of #174.

alanning commented 8 years ago

Cool, then I won't create a new issue.

thomasmery commented 8 years ago

Many thanks!

I guess I did not search well enough