Skip to content

Commit

Permalink
Merge pull request #27 from sadfuzzy/master
Browse files Browse the repository at this point in the history
Update for redmine 2.6.
  • Loading branch information
ka8725 committed Dec 2, 2014
2 parents df02f7c + 078d9ee commit 55cfb28
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/redmine_s3/attachments_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def self.included(base) # :nodoc:
# Same as typing in the class
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
before_filter :download_from_s3, :except => [:destroy, :upload]
before_filter :find_attachment_s3, :only => [:show, :download, :thumbnail]
before_filter :find_editable_attachments_s3, :only => [:edit, :update]
skip_before_filter :file_readable
end
end
Expand All @@ -16,7 +17,7 @@ module ClassMethods
end

module InstanceMethods
def download_from_s3
def find_attachment_s3
if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project)
@attachment.increment_download
end
Expand All @@ -29,6 +30,20 @@ def download_from_s3
redirect_to(RedmineS3::Connection.object_url(@attachment.disk_filename))
end
end

def find_editable_attachments_s3
if @attachments
@attachments.each { |a| a.increment_download }
end
if RedmineS3::Connection.proxy?
@attachments.each do |attachment|
send_data RedmineS3::Connection.get(attachment.disk_filename),
:filename => filename_for_content_disposition(attachment.filename),
:type => detect_content_type(attachment),
:disposition => (attachment.image? ? 'inline' : 'attachment')
end
end
end
end
end
end

0 comments on commit 55cfb28

Please sign in to comment.