I’m using alanning:roles to store roles, with groups, and am trying to get all the Users in a certain Group.
However, if I update a users’s roles for a particular Group, the new array of roles (specifically for that Group only) isn’t getting published.
I believe this is because roles as an array has to be marked as “changed” manually - so trying to do it via below code, but not quite there (see comment in code):
Any tips?
EDIT: I don’t want to use v2.0 of alanning:roles - can’t migrate right now.
Meteor.publish('groupUsersPub', function(groupId){
var self = this;
var rolesKey = 'roles.'+groupId;
var users = Meteor.users.find(
{},
{
fields: {
'emails.address': 1,
'services.password.reset.reason': 1,
[rolesKey]:1
}
}
);
//tried this but does not work - says it cannot find element with [userId]
_.each(users.fetch() , function(user){
self.changed(users, user._id, user);
});
console.log(users.fetch());
return users;
return self.ready();
});