Class: Groups::AutocompleteService

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

Constant Summary collapse

SEARCH_LIMIT =
5

Constants inherited from BaseService

BaseService::UnauthorizedError

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



48
49
50
51
52
# File 'app/services/groups/autocomplete_service.rb', line 48

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

  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
# 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_params[:include_descendants] = true

  relation = WorkItems::WorkItemsFinder.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



44
45
46
# File 'app/services/groups/autocomplete_service.rb', line 44

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

#merge_requestsObject

rubocop: disable CodeReuse/ActiveRecord



28
29
30
31
32
33
# File 'app/services/groups/autocomplete_service.rb', line 28

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



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

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