2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-26 22:06:19 -04:00
|
|
|
class AutocompleteController < ApplicationController
|
2019-03-09 07:22:58 -05:00
|
|
|
skip_before_action :authenticate_user!, only: [:users, :award_emojis, :merge_request_target_branches]
|
2015-07-10 20:36:24 -04:00
|
|
|
|
2015-03-26 22:06:19 -04:00
|
|
|
def users
|
2018-07-30 11:45:49 -04:00
|
|
|
project = Autocomplete::ProjectFinder
|
|
|
|
.new(current_user, params)
|
|
|
|
.execute
|
2016-05-16 10:24:51 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
group = Autocomplete::GroupFinder
|
|
|
|
.new(current_user, project, params)
|
|
|
|
.execute
|
2016-05-16 10:24:51 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
users = Autocomplete::UsersFinder
|
|
|
|
.new(params: params, current_user: current_user, project: project, group: group)
|
|
|
|
.execute
|
2017-08-30 03:48:55 -04:00
|
|
|
|
2019-08-01 12:51:14 -04:00
|
|
|
render json: UserSerializer.new(params).represent(users, project: project)
|
2017-08-30 03:48:55 -04:00
|
|
|
end
|
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
def user
|
2018-10-18 05:06:44 -04:00
|
|
|
user = UserFinder.new(params[:id]).find_by_id!
|
2017-11-14 04:02:39 -05:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
render json: UserSerializer.new.represent(user)
|
2015-11-19 08:49:35 -05:00
|
|
|
end
|
2016-08-16 05:46:08 -04:00
|
|
|
|
2018-07-30 11:45:49 -04: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 04:02:39 -05:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
render json: MoveToProjectSerializer.new.represent(projects)
|
2016-08-16 05:46:08 -04:00
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
def award_emojis
|
2019-06-18 01:15:53 -04:00
|
|
|
render json: AwardEmojis::CollectUserEmojiService.new(current_user).execute
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2019-03-09 07:22:58 -05:00
|
|
|
|
|
|
|
def merge_request_target_branches
|
|
|
|
merge_requests = MergeRequestsFinder.new(current_user, params).execute
|
|
|
|
target_branches = merge_requests.recent_target_branches
|
|
|
|
|
|
|
|
render json: target_branches.map { |target_branch| { title: target_branch } }
|
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|