Commit 4911f5af authored by Timothy Andrew's avatar Timothy Andrew Committed by Alfredo Sumaran

Only show users that have the `push_code` ability.

- While selecting user access for a protected branch.
parent 683a0920
......@@ -103,7 +103,8 @@ class ProtectedBranchesAccessSelect {
search: query,
per_page: 20,
active: true,
project_id: gon.current_project_id
project_id: gon.current_project_id,
push_code: true
},
dataType: "json"
}).done(function(users) {
......
......@@ -9,15 +9,7 @@ class AutocompleteController < ApplicationController
@users = @users.where.not(id: params[:skip_users]) if params[:skip_users].present?
@users = @users.active
@users = @users.reorder(:name)
if params[:push_code_to_protected_branches].present? && params[:project_id].present?
project = Project.find_by(id: params[:project_id])
@users = @users.to_a.
select { |user| user.can?(:push_code_to_protected_branches, project) }.
take(Kaminari.config.default_per_page)
else
@users = @users.page(params[:page])
end
@users = load_users_by_ability || @users.page(params[:page])
if params[:search].blank?
# Include current user if available to filter by "Me"
......@@ -56,6 +48,19 @@ class AutocompleteController < ApplicationController
private
def load_users_by_ability
ability = :push_code_to_protected_branches if params[:push_code_to_protected_branches].present?
ability = :push_code if params[:push_code].present?
return if params[:project_id].blank?
return if ability.blank?
project = Project.find_by(id: params[:project_id])
@users.to_a.
select { |user| user.can?(ability, project) }.
take(Kaminari.config.default_per_page)
end
def find_users
@users =
if @project
......
......@@ -46,6 +46,21 @@ describe AutocompleteController do
it { expect(body.size).to eq 1 }
it { expect(body.first["username"]).to eq user.username }
end
describe "GET #users that can push code" do
let(:reporter_user) { create(:user) }
before do
project.team << [reporter_user, :reporter]
get(:users, project_id: project.id, push_code: 'true')
end
let(:body) { JSON.parse(response.body) }
it { expect(body).to be_kind_of(Array) }
it { expect(body.size).to eq 2 }
it { expect(body.map { |user| user["username"] }).to match_array([user.username, user2.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