debian-mirror-gitlab/app/controllers/autocomplete_controller.rb

86 lines
2.6 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
class AutocompleteController < ApplicationController
2022-05-07 20:08:51 +05:30
include SearchRateLimitable
2019-07-07 11:18:12 +05:30
skip_before_action :authenticate_user!, only: [:users, :award_emojis, :merge_request_target_branches]
2022-05-07 20:08:51 +05:30
before_action :check_search_rate_limit!, only: [:users, :projects]
2015-09-11 14:41:01 +05:30
2021-01-03 14:25:43 +05:30
feature_category :users, [:users, :user]
feature_category :projects, [:projects]
2021-12-11 22:18:48 +05:30
feature_category :team_planning, [:award_emojis]
2021-01-03 14:25:43 +05:30
feature_category :code_review, [:merge_request_target_branches]
feature_category :continuous_delivery, [:deploy_keys_with_owners]
2022-07-16 23:28:13 +05:30
urgency :low, [:merge_request_target_branches, :deploy_keys_with_owners, :users]
urgency :low, [:award_emojis]
urgency :medium, [:projects]
2022-01-26 12:08:38 +05:30
2015-04-26 12:48:37 +05:30
def users
2018-11-20 20:47:30 +05:30
group = Autocomplete::GroupFinder
.new(current_user, project, params)
.execute
2018-11-20 20:47:30 +05:30
users = Autocomplete::UsersFinder
.new(params: params, current_user: current_user, project: project, group: group)
.execute
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
render json: UserSerializer.new(params.merge({ current_user: current_user })).represent(users, project: project)
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
2018-11-20 20:47:30 +05:30
def user
2018-12-13 13:39:08 +05:30
user = UserFinder.new(params[:id]).find_by_id!
2015-12-23 02:04:40 +05:30
2018-11-20 20:47:30 +05:30
render json: UserSerializer.new.represent(user)
2015-12-23 02:04:40 +05:30
end
2016-09-13 17:45:13 +05:30
2018-11-20 20:47:30 +05:30
# 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
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
render json: MoveToProjectSerializer.new.represent(projects)
2016-09-13 17:45:13 +05:30
end
2018-11-20 20:47:30 +05:30
def award_emojis
2019-12-04 20:38:33 +05:30
render json: AwardEmojis::CollectUserEmojiService.new(current_user).execute
2016-09-13 17:45:13 +05:30
end
2019-07-07 11:18:12 +05:30
def merge_request_target_branches
2020-01-01 13:55:28 +05:30
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-28 23:09:34 +05:30
def deploy_keys_with_owners
2022-08-27 11:52:29 +05:30
deploy_keys = Autocomplete::DeployKeysWithWriteAccessFinder
.new(current_user, project)
.execute
2020-07-28 23:09:34 +05:30
2022-07-23 23:45:48 +05:30
render json: DeployKeys::BasicDeployKeySerializer.new.represent(
deploy_keys, { with_owner: true, user: current_user }
)
2020-07-28 23:09:34 +05:30
end
2020-01-01 13:55:28 +05:30
private
2019-07-07 11:18:12 +05:30
2020-07-28 23:09:34 +05:30
def project
@project ||= Autocomplete::ProjectFinder
.new(current_user, params)
.execute
end
2020-01-01 13:55:28 +05:30
def target_branch_params
params.permit(:group_id, :project_id).select { |_, v| v.present? }
2019-07-07 11:18:12 +05:30
end
2015-04-26 12:48:37 +05:30
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
AutocompleteController.prepend_mod_with('AutocompleteController')