Commit f7f91e84 authored by Nick Thomas's avatar Nick Thomas Committed by Himanshu Kapoor

Add a skip_users filter to the project users API

This functionality is available in the /autocomplete users pseudo-API.
We're attempting to replace that with the canonical API, so it needs
support for this parameter too.
parent bbf639c4
...@@ -855,6 +855,7 @@ GET /projects/:id/users ...@@ -855,6 +855,7 @@ GET /projects/:id/users
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `search` | string | no | Search for specific users | | `search` | string | no | Search for specific users |
| `skip_users` | array[int] | no | Filter out users with the specified IDs |
```json ```json
[ [
......
...@@ -489,11 +489,13 @@ module API ...@@ -489,11 +489,13 @@ module API
end end
params do params do
optional :search, type: String, desc: 'Return list of users matching the search criteria' optional :search, type: String, desc: 'Return list of users matching the search criteria'
optional :skip_users, type: Array[Integer], desc: 'Filter out users with the specified IDs'
use :pagination use :pagination
end end
get ':id/users' do get ':id/users' do
users = DeclarativePolicy.subject_scope { user_project.team.users } users = DeclarativePolicy.subject_scope { user_project.team.users }
users = users.search(params[:search]) if params[:search].present? users = users.search(params[:search]) if params[:search].present?
users = users.where_not_in(params[:skip_users]) if params[:skip_users].present?
present paginate(users), with: Entities::UserBasic present paginate(users), with: Entities::UserBasic
end end
......
...@@ -1494,6 +1494,17 @@ describe API::Projects do ...@@ -1494,6 +1494,17 @@ describe API::Projects do
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
it 'filters out users listed in skip_users' do
other_user = create(:user)
project.team.add_developer(other_user)
get api("/projects/#{project.id}/users?skip_users=#{user.id}", user)
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(1)
expect(json_response[0]['id']).to eq(other_user.id)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment