diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/todo.rb | 14 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
2 files changed, 8 insertions, 10 deletions
diff --git a/app/models/todo.rb b/app/models/todo.rb index b5ca2ec7466..3af2d16deaa 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -66,6 +66,8 @@ class Todo < ApplicationRecord scope :with_entity_associations, -> { preload(:target, :author, :note, group: :route, project: [:route, { namespace: :route }]) } scope :joins_issue_and_assignees, -> { left_joins(issue: :assignees) } + enum resolved_by_action: { system_done: 0, api_all_done: 1, api_done: 2, mark_all_done: 3, mark_done: 4 }, _prefix: :resolved_by + state_machine :state, initial: :pending do event :done do transition [:pending] => :done @@ -100,17 +102,17 @@ class Todo < ApplicationRecord state.nil? ? exists?(target: target) : exists?(target: target, state: state) end - # Updates the state of a relation of todos to the new state. + # Updates attributes of a relation of todos to the new state. # - # new_state - The new state of the todos. + # new_attributes - The new attributes of the todos. # # Returns an `Array` containing the IDs of the updated todos. - def update_state(new_state) - # Only update those that are not really on that state - base = where.not(state: new_state).except(:order) + def batch_update(**new_attributes) + # Only update those that have different state + base = where.not(state: new_attributes[:state]).except(:order) ids = base.pluck(:id) - base.update_all(state: new_state, updated_at: Time.current) + base.update_all(new_attributes.merge(updated_at: Time.current)) ids end diff --git a/app/models/user.rb b/app/models/user.rb index 4311d2e37b1..e2455e667be 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1636,10 +1636,6 @@ class User < ApplicationRecord super.presence || build_user_detail end - def todos_limited_to(ids) - todos.where(id: ids) - end - def pending_todo_for(target) todos.find_by(target: target, state: :pending) end |