gitlab-org--gitlab-foss/app/controllers/autocomplete_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
2.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2015-03-26 22:06:19 -04:00
class AutocompleteController < ApplicationController
include SearchRateLimitable
2019-03-09 07:22:58 -05:00
skip_before_action :authenticate_user!, only: [:users, :award_emojis, :merge_request_target_branches]
before_action :check_search_rate_limit!, only: [:users, :projects]
feature_category :users, [:users, :user]
feature_category :projects, [:projects]
feature_category :team_planning, [:award_emojis]
feature_category :code_review, [:merge_request_target_branches]
feature_category :continuous_delivery, [:deploy_keys_with_owners]
urgency :low, [:merge_request_target_branches, :deploy_keys_with_owners, :users]
urgency :low, [:award_emojis]
urgency :medium, [:projects]
2015-03-26 22:06:19 -04:00
def users
group = Autocomplete::GroupFinder
.new(current_user, project, params)
.execute
users = Autocomplete::UsersFinder
.new(params: params, current_user: current_user, project: project, group: group)
.execute
2017-08-30 03:48:55 -04:00
render json: UserSerializer.new(params.merge({ current_user: current_user })).represent(users, project: project)
2017-08-30 03:48:55 -04:00
end
def user
user = UserFinder.new(params[:id]).find_by_id!
render json: UserSerializer.new.represent(user)
end
# 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
render json: MoveToProjectSerializer.new.represent(projects)
end
def award_emojis
render json: AwardEmojis::CollectUserEmojiService.new(current_user).execute
end
2019-03-09 07:22:58 -05:00
def merge_request_target_branches
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
def deploy_keys_with_owners
deploy_keys = DeployKey.with_write_access_for_project(project)
render json: DeployKeys::BasicDeployKeySerializer.new.represent(
deploy_keys, { with_owner: true, user: current_user }
)
end
private
2019-03-09 07:22:58 -05:00
def project
@project ||= Autocomplete::ProjectFinder
.new(current_user, params)
.execute
end
def target_branch_params
params.permit(:group_id, :project_id).select { |_, v| v.present? }
2019-03-09 07:22:58 -05:00
end
2015-03-26 22:06:19 -04:00
end
AutocompleteController.prepend_mod_with('AutocompleteController')