Class: Groups::AutocompleteService

Inherits:
BaseService show all
Includes:
LabelsAsHash
Defined in:
app/services/groups/autocomplete_service.rb

Constant Summary collapse

SEARCH_LIMIT =
5

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #group, #params

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

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 Groups::BaseService

Instance Method Details

#commands(noteable) ⇒ Object



56
57
58
59
60
# File 'app/services/groups/autocomplete_service.rb', line 56

def commands(noteable)
  return [] unless noteable

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

#issues(confidential_only: false, issue_types: nil) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/groups/autocomplete_service.rb', line 10

def issues(confidential_only: false, issue_types: nil)
  finder_params = { group_id: group.id, state: 'opened' }
  finder_params[:confidential] = true if confidential_only.present?
  finder_params[:issue_types] = issue_types if issue_types.present?

  finder_class =
    if group.namespace_work_items_enabled?
      finder_params[:include_descendants] = true
      WorkItems::WorkItemsFinder
    else
      finder_params[:include_subgroups] = true
      IssuesFinder
    end

  relation = finder_class.new(current_user, finder_params).execute

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

  relation
    .preload(project: :namespace)
    .with_work_item_type
    .select(:iid, :title, :project_id, :namespace_id, 'work_item_types.icon_name')
end

#labels_as_hash(target) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord



52
53
54
# File 'app/services/groups/autocomplete_service.rb', line 52

def labels_as_hash(target)
  super(target, group_id: group.id, only_group_labels: true, include_ancestor_groups: true)
end

#merge_requestsObject

rubocop: disable CodeReuse/ActiveRecord



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

def merge_requests
  MergeRequestsFinder.new(current_user, group_id: group.id, include_subgroups: true, state: 'opened')
    .execute
    .preload(target_project: :namespace)
    .select(:iid, :title, :target_project_id)
end

#milestonesObject

rubocop: disable CodeReuse/ActiveRecord



45
46
47
48
49
# File 'app/services/groups/autocomplete_service.rb', line 45

def milestones
  group_ids = group.self_and_ancestors.public_or_visible_to_user(current_user).pluck(:id)

  MilestonesFinder.new(group_ids: group_ids).execute.select(:iid, :title, :due_date)
end