Fixed loosing assignments when updating a task.
This commit is contained in:
parent
93f4239db6
commit
3e9ca336a8
1 changed files with 2 additions and 5 deletions
|
@ -66,13 +66,10 @@ class Task < ActiveRecord::Base
|
||||||
# and makes the users responsible for the task
|
# and makes the users responsible for the task
|
||||||
# TODO: check for maximal number of users
|
# TODO: check for maximal number of users
|
||||||
def user_list=(ids)
|
def user_list=(ids)
|
||||||
list = ids.split(",")
|
list = ids.split(",").map(&:to_i)
|
||||||
new_users = (list - users.collect(&:id)).uniq
|
new_users = (list - users.collect(&:id)).uniq
|
||||||
old_users = users.reject { |user| list.include?(user.id) }
|
old_users = users.reject { |user| list.include?(user.id) }
|
||||||
|
|
||||||
logger.debug "[debug] New users: #{new_users}"
|
|
||||||
logger.debug "Old users: #{old_users}"
|
|
||||||
|
|
||||||
self.class.transaction do
|
self.class.transaction do
|
||||||
# delete old assignments
|
# delete old assignments
|
||||||
if old_users.any?
|
if old_users.any?
|
||||||
|
@ -84,7 +81,7 @@ class Task < ActiveRecord::Base
|
||||||
if user.blank?
|
if user.blank?
|
||||||
errors.add(:user_list)
|
errors.add(:user_list)
|
||||||
else
|
else
|
||||||
if id == current_user_id
|
if id == current_user_id.to_i
|
||||||
# current_user will accept, when he puts himself to the list of users
|
# current_user will accept, when he puts himself to the list of users
|
||||||
self.assignments.build :user => user, :accepted => true
|
self.assignments.build :user => user, :accepted => true
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue