Better exception handling when a file is physically missing

This commit is contained in:
Karel Picman 2016-03-01 13:15:58 +01:00
parent 5db2aef083
commit 62997ecc0b
11 changed files with 148 additions and 23 deletions

View File

@ -23,10 +23,6 @@
class DmsfController < ApplicationController
unloadable
class ZipMaxFilesError < StandardError; end
class EmailMaxFileSize < StandardError; end
class FileNotFound < StandardError; end
before_filter :find_project
before_filter :authorize
before_filter :find_folder, :except => [:new, :create, :edit_root, :save_root]
@ -217,17 +213,15 @@ class DmsfController < ApplicationController
redirect_to :back
else
download_entries(selected_folders, selected_files)
end
rescue ZipMaxFilesError
flash[:error] = l(:error_max_files_exceeded, :number => Setting.plugin_redmine_dmsf['dmsf_max_file_download'])
redirect_to :back
rescue EmailMaxFileSize
flash[:error] = l(:error_max_email_filesize_exceeded, :number => Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'])
redirect_to :back
end
rescue FileNotFound
render_404
rescue DmsfAccessError
render_403
render_403
rescue Exception => e
flash[:error] = e.message
Rails.logger.error e.message
redirect_to :back
end
def tag_changed
@ -518,7 +512,7 @@ class DmsfController < ApplicationController
end
max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i
if max_files > 0 && zip.files.length > max_files
raise ZipMaxFilesError, zip.files.length
raise ZipMaxFilesError#, zip.files.length
end
zip
end

View File

@ -1,6 +1,9 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -60,4 +63,4 @@ class DmsfZip
folder.files.visible.each { |file| self.add_file(file, member, root_path) }
end
end
end

View File

@ -1,8 +1,10 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -21,8 +23,9 @@
DMSF_MAX_NOTIFICATION_RECEIVERS_INFO = 10
# DMSF libraries
require 'redmine_dmsf/patches' #plugin patches
require 'redmine_dmsf/webdav' #DAV4Rack implementation
require 'redmine_dmsf/patches' # plugin patches
require 'redmine_dmsf/webdav' # DAV4Rack implementation
require 'redmine_dmsf/errors' # Exceptions
# Hooks
@ -33,4 +36,5 @@ module RedmineDmsf
end
# Add the plugin view folder into ActionMailer's paths to search
ActionMailer::Base.append_view_path(File.expand_path(File.dirname(__FILE__) + '/../app/views'))
ActionMailer::Base.append_view_path(File.expand_path(
File.dirname(__FILE__) + '/../app/views'))

View File

@ -0,0 +1,28 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'redmine_dmsf/errors/dmsf_access_error.rb'
require 'redmine_dmsf/errors/dmsf_content_error.rb'
require 'redmine_dmsf/errors/dmsf_email_max_file_error.rb'
require 'redmine_dmsf/errors/dmsf_file_not_found_error.rb'
require 'redmine_dmsf/errors/dmsf_lock_error.rb'
require 'redmine_dmsf/errors/dmsf_zip_max_file_error.rb'

View File

@ -1,6 +1,9 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View File

@ -1,6 +1,9 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View File

@ -0,0 +1,32 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class EmailMaxFileSize < StandardError
include Redmine::I18n
def initialize(message = nil)
if message.present?
super message
else
super l(:error_max_email_filesize_exceeded,
:number => Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'])
end
end
end

View File

@ -0,0 +1,23 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class FileNotFound < StandardError
end

View File

@ -1,6 +1,9 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View File

@ -0,0 +1,32 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class ZipMaxFilesError < StandardError
include Redmine::I18n
def initialize(message = nil)
if message.present?
super message
else
super l(:error_max_files_exceeded,
:number => Setting.plugin_redmine_dmsf['dmsf_max_file_download'])
end
end
end

View File

@ -45,7 +45,7 @@ module RedmineDmsf
if available
serving(env)
else
raise NotFound
return fail(403, 'Not Found')
end
end
end