From f7f91e84f71afa6bcf8a22ed181ce719bfbaf35c Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Fri, 16 Aug 2019 15:11:30 +0100 Subject: 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. --- doc/api/projects.md | 1 + lib/api/projects.rb | 2 ++ spec/requests/api/projects_spec.rb | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/doc/api/projects.md b/doc/api/projects.md index 70df44ec0fd..373607f8f4b 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -855,6 +855,7 @@ GET /projects/:id/users | Attribute | Type | Required | Description | | --------- | ---- | -------- | ----------- | | `search` | string | no | Search for specific users | +| `skip_users` | array[int] | no | Filter out users with the specified IDs | ```json [ diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 996205d4b7b..3073c14b341 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -489,11 +489,13 @@ module API end params do 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 end get ':id/users' do users = DeclarativePolicy.subject_scope { user_project.team.users } 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 end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 1d7ca85cdd2..5465fe0c366 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1494,6 +1494,17 @@ describe API::Projects do expect(response).to have_gitlab_http_status(404) 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 -- cgit v1.2.1