Class: Projects::AutocompleteService

Inherits:
BaseService show all
Includes:
LabelsAsHash, Routing::WikiHelper
Defined in:
app/services/projects/autocomplete_service.rb

Constant Summary collapse

SEARCH_LIMIT =
5

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Routing::WikiHelper

#group_wiki_page_url, #project_wiki_page_url, #wiki_page_path, #wiki_path

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#commands(noteable) ⇒ Object



36
37
38
39
40
# File 'app/services/projects/autocomplete_service.rb', line 36

def commands(noteable)
  return [] unless noteable && current_user

  QuickActions::InterpretService.new(container: project, current_user: current_user).available_commands(noteable)
end

#contacts(target) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/services/projects/autocomplete_service.rb', line 56

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
end

#issuesObject



10
11
12
13
14
15
16
17
18
# File 'app/services/projects/autocomplete_service.rb', line 10

def issues
  relation = IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute

  relation = relation.gfm_autocomplete_search(params[:search]).limit(SEARCH_LIMIT) if params[:search]

  relation
    .with_work_item_type
    .select([:iid, :title, 'work_item_types.icon_name'])
end

#labels_as_hash(target) ⇒ Object



73
74
75
# File 'app/services/projects/autocomplete_service.rb', line 73

def labels_as_hash(target)
  super(target, project_id: project.id, include_ancestor_groups: true)
end

#merge_requestsObject



32
33
34
# File 'app/services/projects/autocomplete_service.rb', line 32

def merge_requests
  MergeRequestsFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
end

#milestonesObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/projects/autocomplete_service.rb', line 20

def milestones
  finder_params = {
    project_ids: [@project.id],
    state: :active,
    order: { due_date: :asc, title: :asc }
  }

  finder_params[:group_ids] = @project.group.self_and_ancestors.select(:id) if @project.group

  MilestonesFinder.new(finder_params).execute.select([:iid, :title, :due_date])
end

#snippetsObject



42
43
44
# File 'app/services/projects/autocomplete_service.rb', line 42

def snippets
  SnippetsFinder.new(current_user, project: project).execute.select([:id, :title])
end

#wikisObject



46
47
48
49
50
51
52
53
54
# File 'app/services/projects/autocomplete_service.rb', line 46

def wikis
  wiki = Wiki.for_container(project, current_user)
  return [] unless can?(current_user, :read_wiki, wiki.container)

  wiki
    .list_pages(limit: 5000, load_content: true, size_limit: 512)
    .reject { |page| page.slug.start_with?('templates/') }
    .map { |page| { path: wiki_page_path(page.wiki, page), slug: page.slug, title: page.human_title } }
end