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
This commit is contained in:
Jean-Philippe Lang
2012-02-23 10:01:16 +00:00
parent d086683b17
commit 77626ef6fb
10 changed files with 175 additions and 19 deletions

View File

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