diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2017-02-18 12:06:22 +0300 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2017-02-18 12:06:22 +0300 |
commit | 6eb45df2fd62c85920c3ef025d7dacadcda05bf4 (patch) | |
tree | 0fb4cdc4e765e1ab48ddf17cba4b179b68dcc4a2 /app/services | |
parent | 5f3f6ee605f3151214030835d058199fddac46fd (diff) | |
parent | 26160459b56019f445a7d29abc0b72f591e1d2a9 (diff) |
Merge branch '25465-todo-done-clicking-is-kind-of-unsafe' into 'master'
Todo done clicking is kind of unusable.
Closes #25465
See merge request !8691
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/todo_service.rb | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index 8ab943f4639..ad86b4f9f42 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -170,16 +170,20 @@ class TodoService # When user marks some todos as done def mark_todos_as_done(todos, current_user) - mark_todos_as_done_by_ids(todos.select(&:id), current_user) + update_todos_state_by_ids(todos.select(&:id), current_user, :done) end def mark_todos_as_done_by_ids(ids, current_user) - todos = current_user.todos.where(id: ids) + update_todos_state_by_ids(ids, current_user, :done) + end - # Only return those that are not really on that state - marked_todos = todos.where.not(state: :done).update_all(state: :done) - current_user.update_todos_count_cache - marked_todos + # When user marks some todos as pending + def mark_todos_as_pending(todos, current_user) + update_todos_state_by_ids(todos.select(&:id), current_user, :pending) + end + + def mark_todos_as_pending_by_ids(ids, current_user) + update_todos_state_by_ids(ids, current_user, :pending) end # When user marks an issue as todo @@ -194,6 +198,15 @@ class TodoService private + def update_todos_state_by_ids(ids, current_user, state) + todos = current_user.todos.where(id: ids) + + # Only return those that are not really on that state + marked_todos = todos.where.not(state: state).update_all(state: state) + current_user.update_todos_count_cache + marked_todos + end + def create_todos(users, attributes) Array(users).map do |user| next if pending_todos(user, attributes).exists? |