Add filtering active and human users in GraphQL
What does this MR do and why?
This MR adds filtering of the users
GraphQL field to return only human users
and only active users, through new optional active: BOOLEAN
and
human: BOOLEAN
arguments.
When the arguments are not provided the field will return the same users as it does currently.
UsersFinder
has been updated to allow scoping only human users.
This work is to allows returning only active human users within a user mapping search.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
In a Rails console find an active user, deactivated user, and bot user
active_user = User.active.take
deactivated_user = User.deactivated.take
bot_user = User.bots.take
Find their Global IDs, which will be passed in as the ids:
argument to the GraphQL Query.users
field:
active_user.to_global_id.to_s
deactivated_user.to_global_id.to_s
bot_user.to_global_id.to_s
Make queries passing in those user IDs. Note that UsersFinder
's definition of active
excludes non-internal users due to the User
scope so you can't find active bot users. This is also the behaviour of the REST API. It seems best to use existing finder-supplied scoping.
Only humans:
{
users(humans: true, ids: [<GLOBAL_ID>]) {
nodes {
username
}
}
}
Only active (non-internal) users:
{
users(active: true, ids: [<GLOBAL_ID>]) {
nodes {
username
}
}
}
Related to #471933