Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ Here is a full list of new async functions:
* userIsInRoleAsync
* getRolesForUserAsync
* getUsersInRoleAsync
* getUserIdsInRoleAsync
* getGroupsForUserAsync
* getScopesForUserAsync
* renameScopeAsync
Expand Down
25 changes: 25 additions & 0 deletions definitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,31 @@ declare namespace Roles {
queryOptions?: QueryOptions
): Promise<Mongo.Cursor<Meteor.User>>

/**
* Retrieve all userIds who are in target role.
*
* Options:
*
* @method getUserIdsInRole
* @param {Array|String} roles Name of role or an array of roles. If array, users
* returned will have at least one of the roles
* specified but need not have _all_ roles.
* Roles do not have to exist.
* @param {Object|String} options Options:
* - `scope`: name of the scope to restrict roles to; user's global
* roles will also be checked
* - `anyScope`: if set, role can be in any scope (`scope` option is ignored)
* - `onlyScoped`: if set, only roles in the specified scope are returned
*/
function getUserIdsInRole(
roles: string | string[],
options?: string | { scope?: string; anyScope?: boolean; onlyScoped?: boolean }
): string[]
function getUserIdsInRoleAsync(
roles: string | string[],
options?: string | { scope?: string; anyScope?: boolean; onlyScoped?: boolean }
): Promise<string[]>

/**
* Remove users from assigned roles.
*
Expand Down
21 changes: 21 additions & 0 deletions roles/roles_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,27 @@ Object.assign(Roles, {
return Meteor.users.find({ _id: { $in: ids } }, ((options && options.queryOptions) || queryOptions) || {})
},

/**
* Retrieve all user IDs who are in target role.
*
* @method getUserIdsInRole
* @param {Array|String} roles Name of role or an array of roles. If array, users
* returned will have at least one of the roles
* specified but need not have _all_ roles.
* Roles do not have to exist.
* @param {Object|String} [options] Options:
* - `scope`: name of the scope to restrict roles to; user's global
* roles will also be checked
* - `anyScope`: if set, role can be in any scope (`scope` option is ignored)
* * @return {Array} Array of user IDs in roles.
* @static
*/
getUserIdsInRole: function (roles, options) {
const ids = Roles.getUserAssignmentsForRole(roles, options).fetch().map(a => a.user._id)

return ids
},

/**
* Retrieve all assignments of a user which are for the target role.
*
Expand Down
23 changes: 23 additions & 0 deletions roles/roles_common_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,29 @@ Object.assign(Roles, {
)
},

/**
* Retrieve all userIds who are in target role.
*
* Options:
*
* @method getUserIdsInRoleAsync
* @param {Array|String} roles Name of role or an array of roles. If array, users
* returned will have at least one of the roles
* specified but need not have _all_ roles.
* Roles do not have to exist.
* @param {Object|String} [options] Options:
* - `scope`: name of the scope to restrict roles to; user's global
* roles will also be checked
* - `anyScope`: if set, role can be in any scope (`scope` option is ignored)
* @return {Promise<Array>} Array of user IDs in roles.
* @static
*/
getUserIdsInRoleAsync: async function (roles, options) {
const cursor = Roles.getUserAssignmentsForRole(roles, options)

return (await cursor.fetchAsync()).map((a) => a.user._id)
},

/**
* Retrieve all assignments of a user which are for the target role.
*
Expand Down
Loading