From cea1a987abcba4878fd0f041d3d233877d85f2fc Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 4 Aug 2010 18:56:33 +0200 Subject: [PATCH] fix display of attachments with acts_as_journalized --- app/models/attachment.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 5005054b..669dc55c 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -28,23 +28,23 @@ class Attachment < ActiveRecord::Base acts_as_journalized :event_title => :filename, :event_url => (Proc.new do |o| { :controller => 'attachments', :action => 'download', - :id => o.id, :filename => o.filename } + :id => o.versioned_id, :filename => o.filename } end), :activity_type => 'files', - :activity_permission => :view_files, - :activity_find_options => {:select => "#{Attachment.table_name}.*", - :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id " + - " AND #{Attachment.table_name}.container_type = 'Version' " + - "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Version.table_name}.project_id " + - " OR ( #{Attachment.table_name}.container_id = #{Project.table_name}.id " + - " AND #{Attachment.table_name}.container_type = 'Project' ) " } + :activity_permission => :view_files - acts_as_activity :type => 'documents', - :permission => :view_documents, - :find_options => {:select => "#{Attachment.table_name}.*", - :joins => "LEFT JOIN #{Document.table_name} ON (#{Document.table_name}.id = #{Attachment.table_name}.container_id" + - " AND #{Attachment.table_name}.container_type='Document') " + - "LEFT JOIN #{Project.table_name} ON (#{Project.table_name}.id = #{Document.table_name}.project_id)" } + acts_as_activity :type => 'documents', :permission => :view_documents + + def activity_type + case container_type + when "Document" + "documents" + when "Version" + "files" + else + super + end + end cattr_accessor :storage_path @@storage_path = "#{RAILS_ROOT}/files"