removing keys with blank values from the mass-assignment

This greens our features again, but it prevents the mass-assignment of
blank values on the move.
pull/413/head
Stefan Frank 11 years ago
parent 80c6927b61
commit ed2ad319c2
  1. 9
      app/models/work_package.rb

@ -530,10 +530,10 @@ class WorkPackage < ActiveRecord::Base
end
# Allow bulk setting of attributes on the work_package
if options[:attributes]
# this is a temporary hack to get to the core of the move: The
params = ActionController::Parameters.new(options[:attributes])
work_package.attributes = params.permit(:assigned_to_id, :responsible_id, :status_id, :start_date, :due_date, :priority_id)
end
# before setting the attributes, we need to remove the move-related fields
work_package.attributes = options[:attributes].except(:copy,:new_project_id, :new_type_id, :follow, :ids)
.reject { |key, value| value.blank? }
end # FIXME this eliminates the case, where values shall be bulk-assigned to null, but this needs to work together with the permit
if options[:copy]
work_package.author = User.current
work_package.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
@ -543,6 +543,7 @@ class WorkPackage < ActiveRecord::Base
self.status
end
end
if work_package.save
unless options[:copy]
# Manually update project_id on related time entries

Loading…
Cancel
Save