From 77626ef6fbf2df028ccf01f6a72e459bfc70e2ab Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 23 Feb 2012 10:01:16 +0000 Subject: Adds support for adding attachments to issues through the REST API (#8171). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8928 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../acts_as_attachable/lib/acts_as_attachable.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'vendor') 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 346e0ab8f..afae0751d 100644 --- a/vendor/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/vendor/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -61,18 +61,23 @@ module Redmine end def save_attachments(attachments, author=User.current) - if attachments && attachments.is_a?(Hash) - attachments.each_value do |attachment| + if attachments.is_a?(Hash) + attachments = attachments.values + end + if attachments.is_a?(Array) + attachments.each 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) + next unless file.size > 0 + a = Attachment.create(:file => file, :author => author) elsif token = attachment['token'] a = Attachment.find_by_token(token) + next unless a + a.filename = attachment['filename'] unless attachment['filename'].blank? + a.content_type = attachment['content_type'] end next unless a + a.description = attachment['description'].to_s.strip if a.new_record? unsaved_attachments << a else -- cgit v1.2.3