2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-27 02:06:19 +00:00
|
|
|
class AutocompleteController < ApplicationController
|
2019-03-09 12:22:58 +00:00
|
|
|
skip_before_action :authenticate_user!, only: [:users, :award_emojis, :merge_request_target_branches]
|
2015-07-11 00:36:24 +00:00
|
|
|
|
2020-10-05 21:08:47 +00:00
|
|
|
feature_category :users, [:users, :user]
|
|
|
|
feature_category :projects, [:projects]
|
|
|
|
feature_category :issue_tracking, [:award_emojis]
|
|
|
|
feature_category :code_review, [:merge_request_target_branches]
|
|
|
|
feature_category :continuous_delivery, [:deploy_keys_with_owners]
|
|
|
|
|
2015-03-27 02:06:19 +00:00
|
|
|
def users
|
2018-07-30 15:45:49 +00:00
|
|
|
group = Autocomplete::GroupFinder
|
|
|
|
.new(current_user, project, params)
|
|
|
|
.execute
|
2016-05-16 14:24:51 +00:00
|
|
|
|
2018-07-30 15:45:49 +00:00
|
|
|
users = Autocomplete::UsersFinder
|
|
|
|
.new(params: params, current_user: current_user, project: project, group: group)
|
|
|
|
.execute
|
2017-08-30 07:48:55 +00:00
|
|
|
|
2021-02-02 12:10:15 +00:00
|
|
|
render json: UserSerializer.new(params.merge({ current_user: current_user })).represent(users, project: project)
|
2017-08-30 07:48:55 +00:00
|
|
|
end
|
|
|
|
|
2018-07-30 15:45:49 +00:00
|
|
|
def user
|
2018-10-18 09:06:44 +00:00
|
|
|
user = UserFinder.new(params[:id]).find_by_id!
|
2017-11-14 09:02:39 +00:00
|
|
|
|
2018-07-30 15:45:49 +00:00
|
|
|
render json: UserSerializer.new.represent(user)
|
2015-11-19 13:49:35 +00:00
|
|
|
end
|
2016-08-16 09:46:08 +00:00
|
|
|
|
2018-07-30 15:45:49 +00:00
|
|
|
# Displays projects to use for the dropdown when moving a resource from one
|
|
|
|
# project to another.
|
|
|
|
def projects
|
|
|
|
projects = Autocomplete::MoveToProjectFinder
|
|
|
|
.new(current_user, params)
|
|
|
|
.execute
|
2017-11-14 09:02:39 +00:00
|
|
|
|
2018-07-30 15:45:49 +00:00
|
|
|
render json: MoveToProjectSerializer.new.represent(projects)
|
2016-08-16 09:46:08 +00:00
|
|
|
end
|
2016-08-05 13:29:20 +00:00
|
|
|
|
2018-07-30 15:45:49 +00:00
|
|
|
def award_emojis
|
2019-06-18 05:15:53 +00:00
|
|
|
render json: AwardEmojis::CollectUserEmojiService.new(current_user).execute
|
2016-08-05 13:29:20 +00:00
|
|
|
end
|
2019-03-09 12:22:58 +00:00
|
|
|
|
|
|
|
def merge_request_target_branches
|
2019-11-30 00:06:03 +00:00
|
|
|
if target_branch_params.present?
|
|
|
|
merge_requests = MergeRequestsFinder.new(current_user, target_branch_params).execute
|
|
|
|
target_branches = merge_requests.recent_target_branches
|
|
|
|
|
|
|
|
render json: target_branches.map { |target_branch| { title: target_branch } }
|
|
|
|
else
|
|
|
|
render json: { error: _('At least one of group_id or project_id must be specified') }, status: :bad_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-15 12:09:26 +00:00
|
|
|
def deploy_keys_with_owners
|
2020-11-10 15:09:14 +00:00
|
|
|
deploy_keys = DeployKey.with_write_access_for_project(project)
|
2020-07-15 12:09:26 +00:00
|
|
|
|
|
|
|
render json: DeployKeySerializer.new.represent(deploy_keys, { with_owner: true, user: current_user })
|
|
|
|
end
|
|
|
|
|
2019-11-30 00:06:03 +00:00
|
|
|
private
|
2019-03-09 12:22:58 +00:00
|
|
|
|
2020-07-15 12:09:26 +00:00
|
|
|
def project
|
|
|
|
@project ||= Autocomplete::ProjectFinder
|
|
|
|
.new(current_user, params)
|
|
|
|
.execute
|
|
|
|
end
|
|
|
|
|
2019-11-30 00:06:03 +00:00
|
|
|
def target_branch_params
|
2019-12-14 00:08:27 +00:00
|
|
|
params.permit(:group_id, :project_id).select { |_, v| v.present? }
|
2019-03-09 12:22:58 +00:00
|
|
|
end
|
2015-03-27 02:06:19 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
AutocompleteController.prepend_if_ee('EE::AutocompleteController')
|