Commit 76d0718c authored by Sean McGivern's avatar Sean McGivern

Fix 500 when selecting a mirror user

When selecting a mirror user, we do a permissions check, which means
that `@users` is an array, not an ActiveRecord relation.

We also can't use `Array#delete`, because it uses `Object#equal?`, while
we need to be able to take advantage of ActiveRecord objects overriding
`#eql?` and `#hash?` (as `Array#uniq` uses a hash internally).
parent b2884238
......@@ -18,8 +18,7 @@ class AutocompleteController < ApplicationController
if params[:search].blank?
# Include current user if available to filter by "Me"
if params[:current_user].present? && current_user
@users = @users.where.not(id: current_user.id)
@users = [current_user, *@users]
@users = [current_user, *@users].uniq
end
if params[:author_id].present?
......
---
title: Fix 500 error when selecting a mirror user
merge_request:
author:
......@@ -61,6 +61,18 @@ describe AutocompleteController do
it { expect(body.size).to eq 2 }
it { expect(body.map { |user| user["username"] }).to match_array([user.username, user2.username]) }
end
describe "GET #users that can push to protected branches, including the current user" do
before do
get(:users, project_id: project.id, push_code_to_protected_branches: true, current_user: true)
end
let(:body) { JSON.parse(response.body) }
it { expect(body).to be_kind_of(Array) }
it { expect(body.size).to eq 1 }
it { expect(body.first["username"]).to eq user.username }
end
end
context 'group members' do
......
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