From bf3f2e19d38f6f3d46c9164b46fc21f9e2de6906 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Thu, 22 Oct 2020 14:17:35 +0000 Subject: [PATCH] shorten long line of app/models/attachment.rb git-svn-id: http://svn.redmine.org/redmine/trunk@20158 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/attachment.rb | 50 ++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index d6c272453..3959a6667 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -32,26 +32,36 @@ class Attachment < ActiveRecord::Base validates_length_of :description, :maximum => 255 validate :validate_max_file_size, :validate_file_extension - acts_as_event :title => :filename, - :url => Proc.new {|o| {:controller => 'attachments', :action => 'show', :id => o.id, :filename => o.filename}} - - acts_as_activity_provider :type => 'files', - :permission => :view_files, - :author_key => :author_id, - :scope => proc { - select("#{Attachment.table_name}.*"). - joins("LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " + - "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id OR ( #{Attachment.table_name}.container_type='Project' AND #{Attachment.table_name}.container_id = #{Project.table_name}.id )") - } - - acts_as_activity_provider :type => 'documents', - :permission => :view_documents, - :author_key => :author_id, - :scope => proc { - select("#{Attachment.table_name}.*"). - joins("LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " + - "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id") - } + acts_as_event( + :title => :filename, + :url => + Proc.new do |o| + {:controller => 'attachments', :action => 'show', + :id => o.id, :filename => o.filename} + end + ) + acts_as_activity_provider( + :type => 'files', + :permission => :view_files, + :author_key => :author_id, + :scope => + proc do + select("#{Attachment.table_name}.*"). + joins("LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " + + "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id OR ( #{Attachment.table_name}.container_type='Project' AND #{Attachment.table_name}.container_id = #{Project.table_name}.id )") + end + ) + acts_as_activity_provider( + :type => 'documents', + :permission => :view_documents, + :author_key => :author_id, + :scope => + proc do + select("#{Attachment.table_name}.*"). + joins("LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " + + "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id") + end + ) cattr_accessor :storage_path @@storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files") -- 2.39.5