Class: TodosFinder
- Inherits:
-
Object
- Object
- TodosFinder
- Includes:
- FinderMethods, FinderWithCrossProjectAccess, Gitlab::Utils::StrongMemoize
- Defined in:
- app/finders/todos_finder.rb
Overview
TodosFinder
Used to filter Todos by set of params
Arguments:
current_user - which user use
params:
action_id: integer
author_id: integer
project_id; integer
target_id; integer
state: 'pending' (default) or 'done'
type: 'Issue' or 'MergeRequest' or ['Issue', 'MergeRequest']
Constant Summary collapse
- NONE =
'0'
- TODO_TYPES =
Set.new(%w[Issue WorkItem MergeRequest DesignManagement::Design AlertManagement::Alert Namespace Project]).freeze
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#params ⇒ Object
Returns the value of attribute params.
Attributes included from FinderWithCrossProjectAccess
#should_skip_cross_project_check
Class Method Summary collapse
Instance Method Summary collapse
-
#any_for_target?(target, state = nil) ⇒ Boolean
Returns ‘true` if the current user has any todos for the given target with the optional given state.
- #execute ⇒ Object
-
#initialize(current_user, params = {}) ⇒ TodosFinder
constructor
A new instance of TodosFinder.
Methods included from FinderMethods
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(current_user, params = {}) ⇒ TodosFinder
Returns a new instance of TodosFinder.
37 38 39 40 |
# File 'app/finders/todos_finder.rb', line 37 def initialize(current_user, params = {}) @current_user = current_user @params = params end |
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
29 30 31 |
# File 'app/finders/todos_finder.rb', line 29 def current_user @current_user end |
#params ⇒ Object
Returns the value of attribute params.
29 30 31 |
# File 'app/finders/todos_finder.rb', line 29 def params @params end |
Class Method Details
.todo_types ⇒ Object
32 33 34 |
# File 'app/finders/todos_finder.rb', line 32 def todo_types TODO_TYPES end |
Instance Method Details
#any_for_target?(target, state = nil) ⇒ Boolean
Returns ‘true` if the current user has any todos for the given target with the optional given state.
target - The value of the ‘target_type` column, such as `Issue`. state - The value of the `state` column, such as `pending` or `done`.
65 66 67 |
# File 'app/finders/todos_finder.rb', line 65 def any_for_target?(target, state = nil) current_user.todos.any_for_target?(target, state) end |
#execute ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/finders/todos_finder.rb', line 42 def execute return Todo.none if current_user.nil? raise ArgumentError, unless valid_types? items = current_user.todos items = by_action_id(items) items = by_action(items) items = (items) items = by_state(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 |