diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-31 03:09:00 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-31 03:09:00 +0000 |
commit | 89cd4b410196971a1259463e6d1121ba85d45a6f (patch) | |
tree | c49eece0b95cd465b2fbd46609027b3eeff02f80 /app | |
parent | 174560aed8a39694ebb6b7a2459d59dbc214c5a9 (diff) | |
download | gitlab-ce-89cd4b410196971a1259463e6d1121ba85d45a6f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/finders/pending_todos_finder.rb | 11 | ||||
-rw-r--r-- | app/models/todo.rb | 4 | ||||
-rw-r--r-- | app/services/todo_service.rb | 15 |
3 files changed, 20 insertions, 10 deletions
diff --git a/app/finders/pending_todos_finder.rb b/app/finders/pending_todos_finder.rb index c21d90c9182..bf1eb07f34e 100644 --- a/app/finders/pending_todos_finder.rb +++ b/app/finders/pending_todos_finder.rb @@ -11,17 +11,18 @@ # change the various `by_*` methods in this finder, without having to touch # everything that uses it. class PendingTodosFinder - attr_reader :current_user, :params + attr_reader :users, :params - # current_user - The user to retrieve the todos for. + # users - The list of users to retrieve the todos for. # params - A Hash containing columns and values to use for filtering todos. - def initialize(current_user, params = {}) - @current_user = current_user + def initialize(users, params = {}) + @users = users @params = params end def execute - todos = current_user.todos.pending + todos = Todo.for_user(users) + todos = todos.pending todos = by_project(todos) todos = by_target_id(todos) todos = by_target_type(todos) diff --git a/app/models/todo.rb b/app/models/todo.rb index 176d5e56fc0..6d6ee07cfaa 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -148,6 +148,10 @@ class Todo < ApplicationRecord .order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')) .order('todos.created_at') end + + def pluck_user_id + pluck(:user_id) + end end def resource_parent diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index dea116c8546..611d9daa2fe 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -177,7 +177,7 @@ class TodoService def resolve_todos_for_target(target, current_user) attributes = attributes_for_target(target) - resolve_todos(pending_todos(current_user, attributes), current_user) + resolve_todos(pending_todos([current_user], attributes), current_user) end def resolve_todos(todos, current_user, resolution: :done, resolved_by_action: :system_done) @@ -220,9 +220,14 @@ class TodoService private def create_todos(users, attributes) - Array(users).map do |user| - next if pending_todos(user, attributes).exists? && Feature.disabled?(:multiple_todos, user) + users = Array(users) + return if users.empty? + + users_with_pending_todos = pending_todos(users, attributes).pluck_user_id + users.reject! { |user| users_with_pending_todos.include?(user.id) && Feature.disabled?(:multiple_todos, user) } + + users.map do |user| issue_type = attributes.delete(:issue_type) track_todo_creation(user, issue_type) @@ -353,8 +358,8 @@ class TodoService end end - def pending_todos(user, criteria = {}) - PendingTodosFinder.new(user, criteria).execute + def pending_todos(users, criteria = {}) + PendingTodosFinder.new(users, criteria).execute end def track_todo_creation(user, issue_type) |