debian-mirror-gitlab/app/services/projects/autocomplete_service.rb

60 lines
1.7 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
module Projects
class AutocompleteService < BaseService
2018-12-05 23:21:45 +05:30
include LabelsAsHash
2016-06-02 11:05:42 +05:30
def issues
2016-09-13 17:45:13 +05:30
IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
2015-04-26 12:48:37 +05:30
end
2016-06-02 11:05:42 +05:30
def milestones
2017-09-10 17:25:29 +05:30
finder_params = {
project_ids: [@project.id],
state: :active,
order: { due_date: :asc, title: :asc }
}
2019-03-02 22:35:43 +05:30
finder_params[:group_ids] = @project.group.self_and_ancestors.select(:id) if @project.group
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
MilestonesFinder.new(finder_params).execute.select([:iid, :title, :due_date])
2015-04-26 12:48:37 +05:30
end
def merge_requests
2016-09-13 17:45:13 +05:30
MergeRequestsFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
2015-04-26 12:48:37 +05:30
end
2016-06-22 15:30:34 +05:30
2016-09-13 17:45:13 +05:30
def commands(noteable, type)
2022-11-25 23:54:43 +05:30
return [] unless noteable && current_user
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
QuickActions::InterpretService.new(project, current_user).available_commands(noteable)
2016-09-13 17:45:13 +05:30
end
2018-12-05 23:21:45 +05:30
def snippets
SnippetsFinder.new(current_user, project: project).execute.select([:id, :title])
end
2022-11-25 23:54:43 +05:30
def contacts(target)
available_contacts = Crm::ContactsFinder.new(current_user, group: project.group).execute
.select([:id, :email, :first_name, :last_name, :state])
contact_hashes = available_contacts.as_json
return contact_hashes unless target.is_a?(Issue)
ids = target.customer_relations_contacts.ids # rubocop:disable CodeReuse/ActiveRecord
contact_hashes.each do |hash|
hash[:set] = ids.include?(hash['id'])
end
contact_hashes
2022-04-04 11:22:00 +05:30
end
2018-12-05 23:21:45 +05:30
def labels_as_hash(target)
super(target, project_id: project.id, include_ancestor_groups: true)
end
2015-04-26 12:48:37 +05:30
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Projects::AutocompleteService.prepend_mod_with('Projects::AutocompleteService')