From 266676d9a9ec0d60a74d922e28f34094f1297da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Fri, 24 Apr 2015 13:32:01 +0200 Subject: [PATCH] Internal Error 500 when dmsf page is accessed #380 --- app/controllers/dmsf_controller.rb | 15 +++++-------- app/controllers/dmsf_links_controller.rb | 11 +++++----- app/controllers/dmsf_upload_controller.rb | 17 ++++----------- app/models/dmsf_link.rb | 14 ++++++------ app/views/dmsf/_dir.html.erb | 26 +++++++++++++---------- app/views/dmsf/_file.html.erb | 2 ++ app/views/dmsf/show.html.erb | 2 +- app/views/dmsf_files/show.html.erb | 2 +- 8 files changed, 39 insertions(+), 50 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 24497ec3..b91025ff 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -240,20 +240,15 @@ class DmsfController < ApplicationController end end - def entries_email - if (Rails::VERSION::MAJOR > 3) - @email_params = e_params - else - @email_params = params[:email] - end - if @email_params[:to].strip.blank? + def entries_email + if params[:email][:to].strip.blank? flash.now[:error] = l(:error_email_to_must_be_entered) render :action => 'email_entries' return end - DmsfMailer.send_documents(@project, User.current, @email_params).deliver - File.delete(@email_params['zipped_content']) - flash[:notice] = l(:notice_email_sent, @email_params['to']) + DmsfMailer.send_documents(@project, User.current, params[:email]).deliver + File.delete(params[:email][:zipped_content]) + flash[:notice] = l(:notice_email_sent, params[:email][:to]) redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder) end diff --git a/app/controllers/dmsf_links_controller.rb b/app/controllers/dmsf_links_controller.rb index c960128b..a49e34f2 100644 --- a/app/controllers/dmsf_links_controller.rb +++ b/app/controllers/dmsf_links_controller.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 +# # Redmine plugin for Document Management System "Features" # # Copyright (C) 2011-15 Karel Pičman @@ -24,12 +26,9 @@ class DmsfLinksController < ApplicationController before_filter :find_link_project before_filter :authorize - def new - if (Rails::VERSION::MAJOR > 3) - @dmsf_link = DmsfLink.new(l_params) - else - @dmsf_link = DmsfLink.new(:project_id => params[:project_id]) - end + def new + @dmsf_link = DmsfLink.new + @dmsf_link.project_id = params[:project_id] if params[:dmsf_link].present? # Reload diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index d88a5562..af1b9638 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -53,12 +53,8 @@ class DmsfUploadController < ApplicationController end # async single file upload handling - def upload_file - if (Rails::VERSION::MAJOR > 3) - @tempfile = params.require(:file) - else - @tempfile = params[:file] - end + def upload_file + @tempfile = params[:file] unless @tempfile.original_filename render_404 return @@ -107,13 +103,8 @@ class DmsfUploadController < ApplicationController end end - def commit_files - if (Rails::VERSION::MAJOR > 3) - commited_files = params.require(:commited_files) - else - commited_files = params[:commited_files] - end - commit_files_internal commited_files + def commit_files + commit_files_internal params[:commited_files] end # REST API file commit diff --git a/app/models/dmsf_link.rb b/app/models/dmsf_link.rb index d34d76fc..f21a5864 100644 --- a/app/models/dmsf_link.rb +++ b/app/models/dmsf_link.rb @@ -95,15 +95,13 @@ class DmsfLink < ActiveRecord::Base end def path - if self.target_type == DmsfFile.model_name - file = self.target_file - path = file.dmsf_path.map { |element| element.is_a?(DmsfFile) ? element.name : element.title }.join('/') if file - else - folder = self.target_folder - path = folder.dmsf_path_str if folder + if self.target_type == DmsfFile.model_name + path = self.target_file.dmsf_path.map { |element| element.is_a?(DmsfFile) ? element.name : element.title }.join('/') if self.target_file + else + path = self.target_folder ? self.target_folder.dmsf_path_str : '' end - path.insert(0, "#{self.target_project.name}:") if self.project_id != self.target_project_id && path - if path.length > 50 + path.insert(0, "#{self.target_project.name}:") if self.project_id != self.target_project_id + if path && path.length > 50 return "#{path[0, 25]}...#{path[-25, 25]}" end path diff --git a/app/views/dmsf/_dir.html.erb b/app/views/dmsf/_dir.html.erb index fe8c073f..4ccf038e 100644 --- a/app/views/dmsf/_dir.html.erb +++ b/app/views/dmsf/_dir.html.erb @@ -20,8 +20,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. %> -<% locked_for_user = subfolder.locked_for_user? %> -<% locked = subfolder.locked? %> +<% locked_for_user = subfolder && subfolder.locked_for_user? %> +<% locked = subfolder && subfolder.locked? %> <%= check_box_tag(name, id, false, :title => l(:title_check_for_zip_download_or_email)) %> @@ -36,7 +36,7 @@ <% end %> -<%= format_time(subfolder.modified) %> +<%= format_time(subfolder.modified) if subfolder %> <% if locked_for_user %> <% if subfolder.lock.reverse[0].user %> <%= link_to('', @@ -54,20 +54,24 @@ -<%= h(subfolder.user) %> +<%= h(subfolder.user) if subfolder %> <% if @folder_manipulation_allowed %>
<% unless locked %> <%= link_to('', edit_dmsf_path(:id => project, :folder_id => subfolder), - :title => l(:link_edit, :title => h(subfolder.title)), + :title => l(:link_edit, :title => subfolder ? h(subfolder.title) : project.name), :class => 'icon icon-edit') %> - <%= link_to('', - lock_dmsf_path(:id => project, :folder_id => subfolder), - :title => l(:title_lock_file), - :class => 'icon icon-dmsf-lock') %> - <% if subfolder.notification %> + <% if subfolder %> + <%= link_to('', + lock_dmsf_path(:id => project, :folder_id => subfolder), + :title => l(:title_lock_file), + :class => 'icon icon-dmsf-lock') %> + <% else %> + + <% end %> + <% if (subfolder && subfolder.notification) || (!subfolder && project.dmsf_notification) %> <%= link_to('', notify_deactivate_dmsf_path(:id => project, :folder_id => subfolder), :title => l(:title_notifications_active_deactivate), @@ -106,5 +110,5 @@ 0 0 -<%= subfolder.updated_at.to_i %> +<%= subfolder.updated_at.to_i if subfolder %> 0 \ No newline at end of file diff --git a/app/views/dmsf/_file.html.erb b/app/views/dmsf/_file.html.erb index 3e201646..2d9e0058 100644 --- a/app/views/dmsf/_file.html.erb +++ b/app/views/dmsf/_file.html.erb @@ -1,4 +1,6 @@ <%#= +# encode: utf-8 +# # Redmine plugin for Document Management System "Features" # # Copyright (C) 2011-15 Karel Pičman diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index ac20e7ae..4e76ba60 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -154,7 +154,7 @@ <% end %> <% @dir_links.each do |link| %> - <% unless (link.target_project && link.target_folder) %> + <% unless link.target_project %> <% Rails.logger.error "Error: dmsf_link id #{link.id} has no target!" %> <% next %> <% end %> diff --git a/app/views/dmsf_files/show.html.erb b/app/views/dmsf_files/show.html.erb index a82445c1..aec16f88 100644 --- a/app/views/dmsf_files/show.html.erb +++ b/app/views/dmsf_files/show.html.erb @@ -90,7 +90,7 @@ <%= l(:info_revision, :rev => revision.id) %> <%= (revision.source_revision.nil? ? l(:label_created) : l(:label_changed)).downcase %> <%= l(:info_changed_by_user, :changed => format_time(revision.updated_at)) %> - <%= link_to(revision.user.name, user_path(revision.user)) %> + <%= link_to(revision.user.name, user_path(revision.user)) if revision.user %>