1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-22 08:21:14 +00:00

shorten long line of app/models/attachment.rb

git-svn-id: http://svn.redmine.org/redmine/trunk@20158 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2020-10-22 14:17:35 +00:00
parent 5c14d09e25
commit bf3f2e19d3

View File

@ -32,26 +32,36 @@ class Attachment < ActiveRecord::Base
validates_length_of :description, :maximum => 255 validates_length_of :description, :maximum => 255
validate :validate_max_file_size, :validate_file_extension validate :validate_max_file_size, :validate_file_extension
acts_as_event :title => :filename, acts_as_event(
:url => Proc.new {|o| {:controller => 'attachments', :action => 'show', :id => o.id, :filename => o.filename}} :title => :filename,
:url =>
acts_as_activity_provider :type => 'files', Proc.new do |o|
:permission => :view_files, {:controller => 'attachments', :action => 'show',
:author_key => :author_id, :id => o.id, :filename => o.filename}
:scope => proc { end
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 " + acts_as_activity_provider(
"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 )") :type => 'files',
} :permission => :view_files,
:author_key => :author_id,
acts_as_activity_provider :type => 'documents', :scope =>
:permission => :view_documents, proc do
:author_key => :author_id, select("#{Attachment.table_name}.*").
:scope => proc { joins("LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
select("#{Attachment.table_name}.*"). "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 )")
joins("LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " + end
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id") )
} 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 cattr_accessor :storage_path
@@storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files") @@storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")