Fixed loosing assignments when updating a task.

This commit is contained in:
Benjamin Meichsner 2013-04-08 01:30:31 +02:00
parent 13e921a632
commit 03ea8e194e

View file

@ -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