-
-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get a list of users with a scope #388
Comments
Thank you for submitting this issue! We, the Members of Meteor Community Packages take every issue seriously. However, we contribute to these packages mostly in our free time. If you think this issue is trivial to solve, don't hesitate to submit Please also consider sponsoring the maintainers of the package. |
Hi @kjrhody there is Edit: just rechecked and this is not what you actually need, right? Edit edit: I think this needs to be implemented or there needs to be a workaround, @StorytellerCZ what do you think? |
@jankapunkt Thanks for your response! Correct, I'd like to be able to get a list of users who have that scope. Using the example from your documentation below, I'd like to be able to get a list of all the users, regardless of role, who have
|
@kjrhody , you can get the info running this query:
|
I see two things here:
Am I getting that right? |
And here has a list with all methods: https://meteor-community-packages.github.io/meteor-roles/classes/Roles.html#api-classes |
@jankapunkt @StorytellerCZ My need is only one thing, I will see if I can clarify. Using the scope as an argument, I would like to be able to get all the users that have that scope. Something like this would be very helpful:
The method posted above by @ricaragao gets all of the records in that collection with that scope, but if a user has two roles within a scope, it will return both of those records. I just really need a list of users. This would be the equivalent to the current method that is available
|
@ricaragao Thanks, I've tried this and it isn't exactly right. For example, if a user had two roles within the same scope, it would return both of those records. I really just need a list of the users within a scope. If you have further code that condenses the list by user that would be helpful, but if there were a method that didn't make me have to loop through all of those records to check whether the user was the same, that would be preferred. At the moment I'm having to do something like this
|
I think 1. covers @kjrhody's use case, but assuming that in 2. you mean "Get users that have a specific scope with a specific |
@kjrhody to modify @ricaragao's code to fit your your use case you'd just need to use the result to get all the user id's and then run a second lookup to get all the users. The code for this could look something like the following. const findUsersInScope = async (scope) => {
const assignments = await Meteor.roleAssignment.find({ scope }).fetchAsync();
const userIds = assignments.reduce((acc, assignment) => {
return acc.add(assignment.user._id);
}, new Set());
return await Meteor.users.find({ _id: { $in: Array.from(userIds) } }).fetchAsync();
}; |
From my end the question remains if this is solved by this workaround (then I would propose a PR to add this to the Readme as example) or if there is the need for a new Method? |
@jankapunkt I think these would be a useful addition to the package, especially due to the fact that the package doesn't define the |
I see that there is a way to get the users with a specific role, but I'm interested in getting the users with a specific scope.
Say there were a project (Project 1), and the project had different roles. And I had multiple projects on my website (Project 1, Project 2, Project 3). I would like to get everyone associated with Project 1, regardless of their role.
So instead of
Roles.getUsersInRole('user-role')
I guess I'm asking if there's something like
Roles.getUsersInScope('project-name')
This was fairly easy to do in older versions of the package, with a query like this, if a user had been assigned to a project
return Meteor.users.find({"roles.__global_roles__": "project-1"});
But for v3, I didn't see this in the documentation anywhere - is it possible to do this currently?
The text was updated successfully, but these errors were encountered: