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

Help! Can't update roles for user #141

Closed chinhnguyen90 closed 8 years ago

chinhnguyen90 commented 9 years ago

When i use:

Roles.removeUsersFromRoles(id, roles, group); Roles.addUsersToRoles(id, $meteor.object(Profiles, roles, group);

Report:

Update failed: Access denied. In a restricted collection you can only update documents, not replace them. Use a Mongo update operator, such as '$set'.

alanning commented 9 years ago

Can you rewrite it without the $meteor.object part, please? I'm not familiar with what that does and it will also help serve to narrow down potential issues.

chinhnguyen90 commented 9 years ago

@alanning I declare var profile = $meteor.object(Profiles, profileId).getRawObject(); and Roles.addUsersToRoles(id, profile.roles, group);. It still same issuse .

alanning commented 8 years ago

OK, can you put up a simple repo on Github that reproduces the issue, please?

chinhnguyen90 commented 8 years ago

@alanning This is my repo: https://github.com/lungkuteo/meteor-alanning-test Username: admin Password: 12345678 When login, issue show on console.

alanning commented 8 years ago

The error is not being produced by alanning:roles. I removed all references to Roles and also removed the package from your example app; the same error message appears (along with other errors related to angular).

Somewhere in your app I would guess you are doing an update to a collection without using $set and Meteor isn't letting it go through. I tried finding the problem for you by searching for ".update" but I wasn't able to locate it (seemed like they all used $set).

To find the culprit, I'd recommend progressively cutting out more and more pieces of the app until the error no longer appears. Then you know the last part you cut is the cause. Using a new git repo to track changes while debugging is especially useful.

Sorry I can't be of more help. When you do track it down, please update this issue as I'm curious about the actual source of the error message.

chinhnguyen90 commented 8 years ago

Ok, thank you so much!