Class: TodosFinder

Inherits:
Object
  • Object
show all
Includes:
FinderMethods, FinderWithCrossProjectAccess, Gitlab::Utils::StrongMemoize, SafeFormatHelper
Defined in:
app/finders/todos_finder.rb

Overview

TodosFinder

Used to filter Todos by set of params

Arguments:

users: which user or users, provided as a list, to use.
action_id: integer
author_id: integer
project_id; integer
target_id; integer
state: 'pending' (default) or 'done'
is_snoozed: boolean
type: 'Issue' or 'MergeRequest' or ['Issue', 'MergeRequest']

Constant Summary collapse

NONE =
'0'
TODO_TYPES =
Set.new(
  %w[Commit Issue WorkItem MergeRequest DesignManagement::Design AlertManagement::Alert Namespace Project Key
    WikiPage::Meta]
).freeze

Instance Attribute Summary collapse

Attributes included from FinderWithCrossProjectAccess

#should_skip_cross_project_check

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SafeFormatHelper

#safe_format, #tag_pair

Methods included from FinderMethods

#find, #find_by, #find_by!

Methods included from FinderWithCrossProjectAccess

#can_read_cross_project?, #can_read_project?, #find, #find_by, #find_by!, #skip_cross_project_check

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Constructor Details

#initialize(users:, **params) ⇒ TodosFinder

Returns a new instance of TodosFinder.



41
42
43
44
45
# File 'app/finders/todos_finder.rb', line 41

def initialize(users:, **params)
  @users = users
  @params = params
  self.should_skip_cross_project_check = true if skip_cross_project_check?
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



33
34
35
# File 'app/finders/todos_finder.rb', line 33

def params
  @params
end

Class Method Details

.todo_typesObject



36
37
38
# File 'app/finders/todos_finder.rb', line 36

def todo_types
  TODO_TYPES
end

Instance Method Details

#executeObject

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/finders/todos_finder.rb', line 47

def execute
  return Todo.none if users.blank?
  raise ArgumentError, invalid_type_message unless valid_types?

  items = Todo.for_user(users)
  items = without_hidden(items)
  items = by_action_id(items)
  items = by_action(items)
  items = by_author(items)
  items = by_state(items)
  items = by_snoozed_status(items)
  items = by_target_id(items)
  items = by_types(items)
  items = by_group(items)
  # Filtering by project HAS TO be the last because we use
  # the project IDs yielded by the todos query thus far
  items = by_project(items)

  sort(items)
end