I'm trying to make an admin section on my website. The admin can go to the admin page and see a table of the users in his group. I only want to publish a the users that are in that admin's group. E.g. he is in the group ['soccer'] but I wouldn't want him to see all users in the ['hockey'] group. A user can be in more than one group but I should be able to figure that out once I understand how to query it.
Anyways, here's what I have so far:
Meteor.publish('users', function() {
groups = Roles.getGroupsForUser(this.userId)
group = groups[0] //Just get the first group for now
// If the user is an admin of any group (the first one in the array)
if (Roles.userIsInRole(this.userId, ['admin'], group)) {
return Meteor.users.find({roles: {$in: groups}},
{fields: {emails: 1,
createdAt: 1,
roles: 1
}
});
} else {
console.log('null')
return null;
}
});
My subscription in my router:
Meteor.subscribe("users")
Now when I replace:
{roles: {$in: groups}}
with just:
{}
It works, but my table contains all users instead of just the users of a group. What query should I put to make this work? I'm using the roles package by alanning.
This code has about a 5% chance of working out of the box because I have no collection to test this on, I have no way of running this code, I don't have the roles package, I don't have your users database, and I've never done .map on a cursor before, haha.
/server/methods.js
/client/somethingsomething.js
And then in your helpers:
/client/somethingsomething.html