summaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-02-16 21:00:11 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-02-16 21:00:11 +0000
commitd4e6355eb3f220787e9374eeef6fb496f213f0d1 (patch)
tree1fe20acbf595c1df2407cc563ed37acf74292c10 /vendor
parenta8f98bb74903954f28c4299f4ea7a7279d9028dd (diff)
downloadredmine-d4e6355eb3f220787e9374eeef6fb496f213f0d1.tar.gz
redmine-d4e6355eb3f220787e9374eeef6fb496f213f0d1.zip
Better handling of attachments when issue validation fails (#10253).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8891 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'vendor')
-rw-r--r--vendor/plugins/acts_as_attachable/lib/acts_as_attachable.rb39
1 files changed, 38 insertions, 1 deletions
diff --git a/vendor/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/vendor/plugins/acts_as_attachable/lib/acts_as_attachable.rb
index e840770a3..346e0ab8f 100644
--- a/vendor/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/vendor/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -32,8 +32,8 @@ module Redmine
has_many :attachments, options.merge(:as => :container,
:order => "#{Attachment.table_name}.created_on",
:dependent => :destroy)
- attr_accessor :unsaved_attachments
send :include, Redmine::Acts::Attachable::InstanceMethods
+ before_save :attach_saved_attachments
end
end
@@ -52,6 +52,43 @@ module Redmine
user.allowed_to?(self.class.attachable_options[:delete_permission], self.project)
end
+ def saved_attachments
+ @saved_attachments ||= []
+ end
+
+ def unsaved_attachments
+ @unsaved_attachments ||= []
+ end
+
+ def save_attachments(attachments, author=User.current)
+ if attachments && attachments.is_a?(Hash)
+ attachments.each_value do |attachment|
+ a = nil
+ if file = attachment['file']
+ next unless file && file.size > 0
+ a = Attachment.create(:file => file,
+ :description => attachment['description'].to_s.strip,
+ :author => author)
+ elsif token = attachment['token']
+ a = Attachment.find_by_token(token)
+ end
+ next unless a
+ if a.new_record?
+ unsaved_attachments << a
+ else
+ saved_attachments << a
+ end
+ end
+ end
+ {:files => saved_attachments, :unsaved => unsaved_attachments}
+ end
+
+ def attach_saved_attachments
+ saved_attachments.each do |attachment|
+ self.attachments << attachment
+ end
+ end
+
module ClassMethods
end
end