summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-23 09:16:14 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-23 09:16:14 +0000
commitef45304817e9eeca5bc80b26a06594a4165f38cd (patch)
tree77434a1893c7a8dce9c34f8a12a22922f9d91c50 /lib/plugins
parentc91a4391d34b9bd97270d20f04aeb40ee64166a1 (diff)
downloadredmine-ef45304817e9eeca5bc80b26a06594a4165f38cd.tar.gz
redmine-ef45304817e9eeca5bc80b26a06594a4165f38cd.zip
Adds file custom field format (#6719).
git-svn-id: http://svn.redmine.org/redmine/trunk@15917 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb11
-rw-r--r--lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb15
2 files changed, 13 insertions, 13 deletions
diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
index bc4242564..2e5fc841c 100644
--- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -34,6 +34,7 @@ module Redmine
options.merge(:as => :container, :dependent => :destroy, :inverse_of => :container)
send :include, Redmine::Acts::Attachable::InstanceMethods
before_save :attach_saved_attachments
+ after_rollback :detach_saved_attachments
validate :warn_about_failed_attachments
end
end
@@ -90,7 +91,7 @@ module Redmine
if file = attachment['file']
next unless file.size > 0
a = Attachment.create(:file => file, :author => author)
- elsif token = attachment['token']
+ elsif token = attachment['token'].presence
a = Attachment.find_by_token(token)
unless a
@failed_attachment_count += 1
@@ -117,6 +118,14 @@ module Redmine
end
end
+ def detach_saved_attachments
+ saved_attachments.each do |attachment|
+ # TODO: use #reload instead, after upgrading to Rails 5
+ # (after_rollback is called when running transactional tests in Rails 4)
+ attachment.container = nil
+ end
+ end
+
def warn_about_failed_attachments
if @failed_attachment_count && @failed_attachment_count > 0
errors.add :base, ::I18n.t('warning_attachments_not_saved', count: @failed_attachment_count)
diff --git a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index f9da79c22..fb5edf0fc 100644
--- a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -68,16 +68,7 @@ module Redmine
custom_field_values.each do |custom_field_value|
key = custom_field_value.custom_field_id.to_s
if values.has_key?(key)
- value = values[key]
- if value.is_a?(Array)
- value = value.reject(&:blank?).map(&:to_s).uniq
- if value.empty?
- value << ''
- end
- else
- value = value.to_s
- end
- custom_field_value.value = value
+ custom_field_value.value = values[key]
end
end
@custom_field_values_changed = true
@@ -93,11 +84,11 @@ module Redmine
if values.empty?
values << custom_values.build(:customized => self, :custom_field => field)
end
- x.value = values.map(&:value)
+ x.instance_variable_set("@value", values.map(&:value))
else
cv = custom_values.detect { |v| v.custom_field == field }
cv ||= custom_values.build(:customized => self, :custom_field => field)
- x.value = cv.value
+ x.instance_variable_set("@value", cv.value)
end
x.value_was = x.value.dup if x.value
x