From 303504df4788fead8ab200dd5490658489ba5385 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 29 Apr 2017 12:29:59 +0000 Subject: Revert "Merge branch 'tc-no-todo-service-select' into 'master'" This reverts merge request !10845 --- app/controllers/dashboard/todos_controller.rb | 4 ++-- app/services/issuable_base_service.rb | 2 +- app/services/todo_service.rb | 16 ++++++---------- 3 files changed, 9 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb index 2b76e57c06a..4d7d45787fc 100644 --- a/app/controllers/dashboard/todos_controller.rb +++ b/app/controllers/dashboard/todos_controller.rb @@ -12,7 +12,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController end def destroy - TodoService.new.mark_todos_as_done_by_ids(params[:id], current_user) + TodoService.new.mark_todos_as_done_by_ids([params[:id]], current_user) respond_to do |format| format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' } @@ -32,7 +32,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController end def restore - TodoService.new.mark_todos_as_pending_by_ids(params[:id], current_user) + TodoService.new.mark_todos_as_pending_by_ids([params[:id]], current_user) render json: todos_counts end diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 17cb71be5f6..b071a398481 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -260,7 +260,7 @@ class IssuableBaseService < BaseService todo_service.mark_todo(issuable, current_user) when 'done' todo = TodosFinder.new(current_user).execute.find_by(target: issuable) - todo_service.mark_todos_as_done_by_ids(todo, current_user) if todo + todo_service.mark_todos_as_done([todo], current_user) if todo end end diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index a19283cccd3..b6e88b0280f 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -170,22 +170,20 @@ class TodoService # When user marks some todos as done def mark_todos_as_done(todos, current_user) - update_todos_state(todos, current_user, :done) + update_todos_state_by_ids(todos.select(&:id), current_user, :done) end def mark_todos_as_done_by_ids(ids, current_user) - todos = todos_by_ids(ids, current_user) - mark_todos_as_done(todos, current_user) + update_todos_state_by_ids(ids, current_user, :done) end # When user marks some todos as pending def mark_todos_as_pending(todos, current_user) - update_todos_state(todos, current_user, :pending) + update_todos_state_by_ids(todos.select(&:id), current_user, :pending) end def mark_todos_as_pending_by_ids(ids, current_user) - todos = todos_by_ids(ids, current_user) - mark_todos_as_pending(todos, current_user) + update_todos_state_by_ids(ids, current_user, :pending) end # When user marks an issue as todo @@ -200,11 +198,9 @@ class TodoService private - def todos_by_ids(ids, current_user) - current_user.todos.where(id: Array(ids)) - end + def update_todos_state_by_ids(ids, current_user, state) + todos = current_user.todos.where(id: ids) - def update_todos_state(todos, current_user, state) # Only update those that are not really on that state todos = todos.where.not(state: state) todos_ids = todos.pluck(:id) -- cgit v1.2.1