diff options
Diffstat (limited to 'app/finders/todos_finder.rb')
-rw-r--r-- | app/finders/todos_finder.rb | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index 672bbd52b07..a2054f73c9d 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -11,7 +11,7 @@ # author_id: integer # project_id; integer # state: 'pending' (default) or 'done' -# type: 'Issue' or 'MergeRequest' +# type: 'Issue' or 'MergeRequest' or ['Issue', 'MergeRequest'] # class TodosFinder @@ -40,13 +40,14 @@ class TodosFinder def execute return Todo.none if current_user.nil? + raise ArgumentError, invalid_type_message unless valid_types? items = current_user.todos items = by_action_id(items) items = by_action(items) items = by_author(items) items = by_state(items) - items = by_type(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 @@ -123,12 +124,16 @@ class TodosFinder end end - def type? - type.present? && self.class.todo_types.include?(type) + def types + @types ||= Array(params[:type]).reject(&:blank?) end - def type - params[:type] + def valid_types? + types.all? { |type| self.class.todo_types.include?(type) } + end + + def invalid_type_message + _("Unsupported todo type passed. Supported todo types are: %{todo_types}") % { todo_types: self.class.todo_types.to_a.join(', ') } end def sort(items) @@ -193,9 +198,9 @@ class TodosFinder items.with_states(params[:state]) end - def by_type(items) - if type? - items.for_type(type) + def by_types(items) + if types.any? + items.for_type(types) else items end |