2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-12 23:33:09 -04:00
|
|
|
class Projects::AutocompleteSourcesController < Projects::ApplicationController
|
2019-02-22 09:31:02 -05:00
|
|
|
before_action :authorize_read_milestone!, only: :milestones
|
2022-01-25 16:15:18 -05:00
|
|
|
before_action :authorize_read_crm_contact!, only: :contacts
|
2019-02-22 09:31:02 -05:00
|
|
|
|
2022-01-25 16:15:18 -05:00
|
|
|
feature_category :team_planning, [:issues, :labels, :milestones, :commands, :contacts]
|
2020-10-08 14:08:32 -04:00
|
|
|
feature_category :code_review, [:merge_requests]
|
|
|
|
feature_category :users, [:members]
|
|
|
|
feature_category :snippets, [:snippets]
|
|
|
|
|
2022-04-28 11:10:08 -04:00
|
|
|
urgency :low, [:merge_requests, :members]
|
2021-12-09 07:15:43 -05:00
|
|
|
|
2016-10-12 23:33:09 -04:00
|
|
|
def members
|
2017-11-27 22:51:03 -05:00
|
|
|
render json: ::Projects::ParticipantsService.new(@project, current_user).execute(target)
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def issues
|
2018-11-01 04:57:09 -04:00
|
|
|
render json: autocomplete_service.issues
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_requests
|
2018-11-01 04:57:09 -04:00
|
|
|
render json: autocomplete_service.merge_requests
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def labels
|
2018-11-01 04:57:09 -04:00
|
|
|
render json: autocomplete_service.labels_as_hash(target)
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def milestones
|
2018-11-01 04:57:09 -04:00
|
|
|
render json: autocomplete_service.milestones
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def commands
|
2018-11-01 04:57:09 -04:00
|
|
|
render json: autocomplete_service.commands(target, params[:type])
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
|
|
|
|
2018-10-05 05:42:38 -04:00
|
|
|
def snippets
|
2018-11-01 04:57:09 -04:00
|
|
|
render json: autocomplete_service.snippets
|
2018-10-05 05:42:38 -04:00
|
|
|
end
|
|
|
|
|
2022-01-25 16:15:18 -05:00
|
|
|
def contacts
|
|
|
|
render json: autocomplete_service.contacts
|
|
|
|
end
|
|
|
|
|
2016-10-12 23:33:09 -04:00
|
|
|
private
|
|
|
|
|
2018-11-01 04:57:09 -04:00
|
|
|
def autocomplete_service
|
2020-11-17 16:09:19 -05:00
|
|
|
@autocomplete_service ||= ::Projects::AutocompleteService.new(@project, current_user, params)
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
|
|
|
|
2017-11-27 22:51:03 -05:00
|
|
|
def target
|
2018-08-09 05:04:12 -04:00
|
|
|
QuickActions::TargetService
|
|
|
|
.new(project, current_user)
|
|
|
|
.execute(params[:type], params[:type_id])
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
2022-01-25 16:15:18 -05:00
|
|
|
|
|
|
|
def authorize_read_crm_contact!
|
|
|
|
render_404 unless can?(current_user, :read_crm_contact, project.root_ancestor)
|
|
|
|
end
|
2016-10-12 23:33:09 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Projects::AutocompleteSourcesController.prepend_mod_with('Projects::AutocompleteSourcesController')
|