Commit 9653ff7a authored by Rémy Coutable's avatar Rémy Coutable

Resolve conflict in app/controllers/autocomplete_controller.rb

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 580f19b8
......@@ -2,40 +2,11 @@ class AutocompleteController < ApplicationController
AWARD_EMOJI_MAX = 100
skip_before_action :authenticate_user!, only: [:users, :award_emojis]
<<<<<<< HEAD
before_action :load_project, only: [:users, :project_groups]
before_action :find_users, only: [:users]
def users
@users = @users.non_ldap if params[:skip_ldap] == 'true'
@users = @users.active
@users = @users.reorder(:name)
@users = @users.search(params[:search]) if params[:search].present?
@users = @users.where.not(id: params[:skip_users]) if params[:skip_users].present?
@users = load_users_by_ability || @users.page(params[:page]).per(params[:per_page])
if params[:todo_filter].present? && current_user
@users = @users.todo_authors(current_user.id, params[:todo_state_filter])
end
if params[:search].blank?
# Include current user if available to filter by "Me"
if params[:current_user].present? && current_user
@users = [current_user, *@users].uniq
end
if params[:author_id].present? && current_user
author = User.find_by_id(params[:author_id])
@users = [author, *@users].uniq if author
end
end
=======
before_action :load_project, only: [:users]
before_action :load_group, only: [:users]
def users
@users = AutocompleteUsersFinder.new(params: params, current_user: current_user, project: @project, group: @group).execute
>>>>>>> ce-com/master
render json: @users, only: [:name, :username, :id], methods: [:avatar_url]
end
......@@ -72,35 +43,9 @@ class AutocompleteController < ApplicationController
private
<<<<<<< HEAD
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?
@users.to_a
.select { |user| user.can?(ability, @project) }
.take(params[:per_page]&.to_i || Kaminari.config.default_per_page)
end
def find_users
@users =
if @project
user_ids = @project.team.users.pluck(:id)
if params[:author_id].present?
user_ids << params[:author_id]
end
User.where(id: user_ids)
elsif params[:group_id].present?
=======
def load_group
@group ||= begin
if @project.blank? && params[:group_id].present?
>>>>>>> ce-com/master
group = Group.find(params[:group_id])
return render_404 unless can?(current_user, :read_group, group)
group
......
......@@ -2,6 +2,9 @@ class AutocompleteUsersFinder
attr_reader :current_user, :project, :group, :search, :skip_users,
:page, :per_page, :author_id, :params
# EE
attr_reader :skip_ldap
def initialize(params:, current_user:, project:, group:)
@current_user = current_user
@project = project
......@@ -12,15 +15,26 @@ class AutocompleteUsersFinder
@per_page = params[:per_page]
@author_id = params[:author_id]
@params = params
# EE
@skip_ldap = params[:skip_ldap]
end
def execute
items = find_users
# EE
items = items.non_ldap if skip_ldap == 'true'
items = items.active
items = items.reorder(:name)
items = items.search(search) if search.present?
items = items.where.not(id: skip_users) if skip_users.present?
items = items.page(page).per(per_page)
# EE
items_by_push_ability = load_users_by_push_ability(items)
items = items.page(page).per(per_page) unless items_by_push_ability
# EE
if params[:todo_filter].present? && current_user
items = items.todo_authors(current_user.id, params[:todo_state_filter])
......@@ -57,4 +71,25 @@ class AutocompleteUsersFinder
User.where(id: user_ids)
end
# EE
def load_users_by_push_ability(items)
return unless project
ability = push_ability
return if ability.blank?
items.to_a
.select { |user| user.can?(ability, project) }
.take(per_page&.to_i || Kaminari.config.default_per_page)
end
def push_ability
if params[:push_code_to_protected_branches].present?
:push_code_to_protected_branches
elsif params[:push_code].present?
:push_code
end
end
# EE
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