diff options
-rw-r--r-- | changelogs/unreleased/41673-blank-query-members-api.yml | 5 | ||||
-rw-r--r-- | lib/api/members.rb | 2 | ||||
-rw-r--r-- | lib/api/v3/members.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/members_spec.rb | 10 | ||||
-rw-r--r-- | spec/requests/api/v3/members_spec.rb | 10 |
5 files changed, 27 insertions, 2 deletions
diff --git a/changelogs/unreleased/41673-blank-query-members-api.yml b/changelogs/unreleased/41673-blank-query-members-api.yml new file mode 100644 index 00000000000..677c5e250c8 --- /dev/null +++ b/changelogs/unreleased/41673-blank-query-members-api.yml @@ -0,0 +1,5 @@ +--- +title: Fix error on empty query for Members API +merge_request: 16235 +author: +type: fixed diff --git a/lib/api/members.rb b/lib/api/members.rb index 5446f6b54b1..130c6d6da71 100644 --- a/lib/api/members.rb +++ b/lib/api/members.rb @@ -22,7 +22,7 @@ module API source = find_source(source_type, params[:id]) users = source.users - users = users.merge(User.search(params[:query])) if params[:query] + users = users.merge(User.search(params[:query])) if params[:query].present? present paginate(users), with: Entities::Member, source: source end diff --git a/lib/api/v3/members.rb b/lib/api/v3/members.rb index de226e4e573..46145cac7a5 100644 --- a/lib/api/v3/members.rb +++ b/lib/api/v3/members.rb @@ -23,7 +23,7 @@ module API source = find_source(source_type, params[:id]) users = source.users - users = users.merge(User.search(params[:query])) if params[:query] + users = users.merge(User.search(params[:query])) if params[:query].present? present paginate(users), with: ::API::Entities::Member, source: source end diff --git a/spec/requests/api/members_spec.rb b/spec/requests/api/members_spec.rb index 5d4f81e07a6..73bd4785b11 100644 --- a/spec/requests/api/members_spec.rb +++ b/spec/requests/api/members_spec.rb @@ -65,6 +65,16 @@ describe API::Members do expect(json_response.count).to eq(1) expect(json_response.first['username']).to eq(master.username) end + + it 'finds all members with no query specified' do + get api("/#{source_type.pluralize}/#{source.id}/members", developer), query: '' + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.count).to eq(2) + expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id] + end end end diff --git a/spec/requests/api/v3/members_spec.rb b/spec/requests/api/v3/members_spec.rb index b91782ae511..de4339ecb8b 100644 --- a/spec/requests/api/v3/members_spec.rb +++ b/spec/requests/api/v3/members_spec.rb @@ -58,6 +58,16 @@ describe API::V3::Members do expect(json_response.count).to eq(1) expect(json_response.first['username']).to eq(master.username) end + + it 'finds all members with no query specified' do + get v3_api("/#{source_type.pluralize}/#{source.id}/members", developer), query: '' + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.count).to eq(2) + expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id] + end end end |