after upgrade 1.5.1 -> 1.5.2. 'top level based search' results in http:500 when 'Documents' is included #408
This commit is contained in:
parent
3a1f88ec53
commit
b2c3158c5a
@ -73,7 +73,7 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
end
|
||||
@dir_links = []
|
||||
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFolder.model_name.name).visible.each do |l|
|
||||
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFolder.model_name.to_s).visible.each do |l|
|
||||
l.target_folder.custom_field_values.each do |v|
|
||||
if v.custom_field_id == params[:custom_field_id].to_i
|
||||
if v.custom_field.compare_values?(v.value, params[:custom_value])
|
||||
@ -84,7 +84,7 @@ class DmsfController < ApplicationController
|
||||
end
|
||||
end
|
||||
@file_links = []
|
||||
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFile.model_name.name).visible.each do |l|
|
||||
DmsfLink.where(:project_id => @project.id, :target_type => DmsfFile.model_name.to_s).visible.each do |l|
|
||||
r = l.target_file.last_revision if l.target_file
|
||||
if r
|
||||
r.custom_field_values.each do |v|
|
||||
@ -157,8 +157,8 @@ class DmsfController < ApplicationController
|
||||
@file_delete_allowed = User.current.allowed_to? :file_delete, @project
|
||||
@subfolders = DmsfFolder.deleted.where(:project_id => @project.id)
|
||||
@files = DmsfFile.deleted.where(:project_id => @project.id)
|
||||
@dir_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFolder.model_name.name)
|
||||
@file_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFile.model_name.name)
|
||||
@dir_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFolder.model_name.to_s)
|
||||
@file_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFile.model_name.to_s)
|
||||
@url_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => 'DmsfUrl')
|
||||
end
|
||||
|
||||
|
||||
@ -105,10 +105,10 @@ class DmsfLinksController < ApplicationController
|
||||
@dmsf_link.target_type = 'DmsfUrl'
|
||||
elsif params[:dmsf_link][:target_file_id].present?
|
||||
@dmsf_link.target_id = params[:dmsf_link][:target_file_id]
|
||||
@dmsf_link.target_type = DmsfFile.model_name.name
|
||||
@dmsf_link.target_type = DmsfFile.model_name.to_s
|
||||
else
|
||||
@dmsf_link.target_id = DmsfLinksHelper.is_a_number?(params[:dmsf_link][:target_folder_id]) ? params[:dmsf_link][:target_folder_id].to_i : nil
|
||||
@dmsf_link.target_type = DmsfFolder.model_name.name
|
||||
@dmsf_link.target_type = DmsfFolder.model_name.to_s
|
||||
end
|
||||
@dmsf_link.name = params[:dmsf_link][:name]
|
||||
|
||||
@ -119,7 +119,7 @@ class DmsfLinksController < ApplicationController
|
||||
@dmsf_file_id = params[:dmsf_link][:dmsf_file_id]
|
||||
@type = params[:dmsf_link][:type]
|
||||
@target_folder_id = params[:dmsf_link][:target_folder_id].to_i if DmsfLinksHelper.is_a_number?(params[:dmsf_link][:target_folder_id])
|
||||
@target_file_id = @dmsf_link.target_id if @dmsf_link.target_type == DmsfFile.model_name.name
|
||||
@target_file_id = @dmsf_link.target_id if @dmsf_link.target_type == DmsfFile.model_name.to_s
|
||||
render :action => 'new'
|
||||
end
|
||||
else
|
||||
@ -133,10 +133,10 @@ class DmsfLinksController < ApplicationController
|
||||
@dmsf_link.target_type = 'DmsfUrl'
|
||||
elsif params[:dmsf_link][:dmsf_file_id].present?
|
||||
@dmsf_link.target_id = params[:dmsf_link][:dmsf_file_id]
|
||||
@dmsf_link.target_type = DmsfFile.model_name.name
|
||||
@dmsf_link.target_type = DmsfFile.model_name.to_s
|
||||
else
|
||||
@dmsf_link.target_id = params[:dmsf_link][:dmsf_folder_id]
|
||||
@dmsf_link.target_type = DmsfFolder.model_name.name
|
||||
@dmsf_link.target_type = DmsfFolder.model_name.to_s
|
||||
end
|
||||
@dmsf_link.name = params[:dmsf_link][:name]
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
:dependent => :destroy
|
||||
has_many :locks, -> { where(entity_type: 0).order("#{DmsfLock.table_name}.updated_at DESC") },
|
||||
:class_name => 'DmsfLock', :foreign_key => 'entity_id', :dependent => :destroy
|
||||
has_many :referenced_links, -> { where target_type: DmsfFile.model_name.name},
|
||||
has_many :referenced_links, -> { where target_type: DmsfFile.model_name.to_s},
|
||||
:class_name => 'DmsfLink', :foreign_key => 'target_id', :dependent => :destroy
|
||||
accepts_nested_attributes_for :revisions, :locks, :referenced_links, :project
|
||||
else
|
||||
@ -54,7 +54,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
:conditions => {:entity_type => 0},
|
||||
:dependent => :destroy
|
||||
has_many :referenced_links, :class_name => 'DmsfLink', :foreign_key => 'target_id',
|
||||
:conditions => {:target_type => DmsfFile.model_name.name}, :dependent => :destroy
|
||||
:conditions => {:target_type => DmsfFile.model_name.to_s}, :dependent => :destroy
|
||||
end
|
||||
|
||||
if (Rails::VERSION::MAJOR > 3)
|
||||
|
||||
@ -318,47 +318,7 @@ class DmsfFolder < ActiveRecord::Base
|
||||
file_links.visible.count +
|
||||
url_links.visible.count
|
||||
end
|
||||
|
||||
# To full fill searchable module expectations in Redmine <= 3.0
|
||||
# TODO: Remove this function in the next release
|
||||
def self.search(tokens, projects = nil, options = {})
|
||||
tokens = [] << tokens unless tokens.is_a?(Array)
|
||||
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
|
||||
|
||||
find_options = {}
|
||||
find_options[:order] = 'dmsf_folders.updated_at ' + (options[:before] ? 'DESC' : 'ASC')
|
||||
|
||||
limit_options = {}
|
||||
limit_options[:limit] = options[:limit] if options[:limit]
|
||||
if options[:offset]
|
||||
limit_options[:conditions] = '(dmsf_folders.updated_at ' + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
|
||||
end
|
||||
|
||||
columns = options[:titles_only] ? ['dmsf_folders.title'] : ['dmsf_folders.title', 'dmsf_folders.description']
|
||||
|
||||
token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
|
||||
|
||||
sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
|
||||
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
|
||||
|
||||
project_conditions = []
|
||||
project_conditions << (Project.allowed_to_condition(User.current, :view_dmsf_files))
|
||||
project_conditions << "project_id IN (#{projects.collect(&:id).join(',')})" if projects
|
||||
|
||||
results = []
|
||||
results_count = 0
|
||||
|
||||
includes(:project).
|
||||
where(project_conditions.join(' AND ')).scoping do
|
||||
where(find_options[:conditions]).order(find_options[:order]).scoping do
|
||||
results_count = count(:all)
|
||||
results = find(:all, limit_options)
|
||||
end
|
||||
end
|
||||
|
||||
[results, results_count]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.directory_subtree(tree, folder, level, current_folder)
|
||||
|
||||
@ -51,7 +51,7 @@ class DmsfLink < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def target_folder_id
|
||||
if self.target_type == DmsfFolder.model_name.name
|
||||
if self.target_type == DmsfFolder.model_name.to_s
|
||||
self.target_id
|
||||
else
|
||||
f = DmsfFile.find_by_id self.target_id
|
||||
@ -64,7 +64,7 @@ class DmsfLink < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def target_file_id
|
||||
self.target_id if self.target_type == DmsfFile.model_name.name
|
||||
self.target_id if self.target_type == DmsfFile.model_name.to_s
|
||||
end
|
||||
|
||||
def target_file
|
||||
|
||||
@ -50,7 +50,7 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest
|
||||
@folder4.delete true
|
||||
assert_nil DmsfFolder.find_by_id(@folder4.id)
|
||||
# TODO: Doesn't work in Travis - a problem with bolean visiblity
|
||||
#assert_equal 0, DmsfLink.where(:target_id => @folder4.id, :target_type => DmsfFolder.model_name.name).count
|
||||
#assert_equal 0, DmsfLink.where(:target_id => @folder4.id, :target_type => DmsfFolder.model_name.to_s).count
|
||||
end
|
||||
|
||||
end
|
||||
@ -50,7 +50,7 @@ class DmsfLinksTest < RedmineDmsf::Test::UnitTest
|
||||
folder_link = DmsfLink.new
|
||||
folder_link.target_project_id = @project1.id
|
||||
folder_link.target_id = @folder1.id
|
||||
folder_link.target_type = DmsfFolder.model_name.name
|
||||
folder_link.target_type = DmsfFolder.model_name.to_s
|
||||
folder_link.name = 'folder1_link2'
|
||||
folder_link.project_id = @project1.id
|
||||
folder_link.created_at = DateTime.now()
|
||||
@ -61,7 +61,7 @@ class DmsfLinksTest < RedmineDmsf::Test::UnitTest
|
||||
file_link = DmsfLink.new
|
||||
file_link.target_project_id = @project1.id
|
||||
file_link.target_id = @file1.id
|
||||
file_link.target_type = DmsfFile.model_name.name
|
||||
file_link.target_type = DmsfFile.model_name.to_s
|
||||
file_link.name = 'file1_link2'
|
||||
file_link.project_id = @project1.id
|
||||
file_link.created_at = DateTime.now()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user