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 167 forks source link

getUsersInRole reactivity? #350

Closed ArosPrince closed 2 years ago

ArosPrince commented 2 years ago

Hi, not sure I am doing everything right, but I noticed this kind of problem on client...

I use getUsersInRole to list admins for my groups (scopes). The exact call looks like this:

Roles.getUsersInRole(['USERS_VIEW', 'USERS_IMPERSONATE'], {
        scope: r.retailerId,
        onlyScoped: true
}).fetch()

It works OK and displays the users it should. But it's only sort of "half reactive". If I update a user name in the DB, it correctly refreshes on the web page.

But if I remove that role from any of the users, it won't update and I need to refresh the page to view the updated list. I use this function server side to remove the role:

Roles.removeUsersFromRoles(users, ['USERS_VIEW', 'USERS_IMPERSONATE'], retailerId);

Do I use it a wrong way, or is this a bug? And if so, what's the best way to workaround it?

ArosPrince commented 2 years ago

This was probably my mistake. Looks like if you want to have a collection reactivity, that line of code has to run in the meteor section and not in VUE's computed section.