summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2022-11-03 05:20:38 +0000
committerGo MAEDA <maeda@farend.jp>2022-11-03 05:20:38 +0000
commit6b5432ef7f5fae0220f563b781bcee6400a09409 (patch)
tree8c16ec371b5f4c2a28fd410682aefbd6c76a6458
parent8277c7bf3a220ec7ae71dd1764c5cfa44e2d5cb1 (diff)
downloadredmine-6b5432ef7f5fae0220f563b781bcee6400a09409.tar.gz
redmine-6b5432ef7f5fae0220f563b781bcee6400a09409.zip
Merged r21948 from trunk to 5.0-stable (#37880).
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@21949 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/attachments_controller.rb19
-rw-r--r--test/functional/attachments_controller_test.rb18
2 files changed, 35 insertions, 2 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 0af43e18c..3bd63337f 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -239,11 +239,28 @@ class AttachmentsController < ApplicationController
if @attachments.sum(&:filesize) > bulk_download_max_size
flash[:error] = l(:error_bulk_download_size_too_big,
:max_size => number_to_human_size(bulk_download_max_size.to_i))
- redirect_to back_url
+ redirect_back_or_default(container_url, referer: true)
return
end
end
+ def container_url
+ case @container
+ when Message
+ url_for(@container.event_url)
+ when Project
+ # project attachments are listed in the files view
+ project_files_url(@container)
+ when Version
+ # version attachments are listed in its project's files view
+ project_files_url(@container.project)
+ when WikiPage
+ project_wiki_page_url @container.wiki.project, @container
+ else
+ url_for(@container)
+ end
+ end
+
# Checks that the file exists and is readable
def file_readable
if @attachment.readable?
diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb
index 7af121788..7b0ded8f9 100644
--- a/test/functional/attachments_controller_test.rb
+++ b/test/functional/attachments_controller_test.rb
@@ -631,7 +631,23 @@ class AttachmentsControllerTest < Redmine::ControllerTest
:params => {
:object_type => 'issues',
:object_id => '2',
- :back_url => '/issues/2'
+ :back_url => '/issues/123'
+ }
+ )
+ assert_redirected_to '/issues/123'
+ assert_equal flash[:error], 'These attachments cannot be bulk downloaded because the total file size exceeds the maximum allowed size (0 Bytes)'
+ end
+ end
+
+ def test_download_all_redirects_to_container_url_on_error
+ with_settings :bulk_download_max_size => 0 do
+ @request.session[:user_id] = 2
+ get(
+ :download_all,
+ :params => {
+ :object_type => 'issues',
+ :object_id => '2',
+ :back_url => 'https://example.com'
}
)
assert_redirected_to '/issues/2'