From 66afc8c054f2b1e7253d9e96d60622d6040bf48d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 21 Feb 2009 15:34:11 +0000 Subject: [PATCH] Adds a setting to limit the size of text attachments that can be displayed by the file viewer (default set to 512KB). Larger files are sent for download. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2503 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/attachments_controller.rb | 2 +- app/views/settings/_general.rhtml | 3 +++ config/locales/bg.yml | 1 + config/locales/ca.yml | 1 + config/locales/cs.yml | 1 + config/locales/da.yml | 1 + config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fi.yml | 1 + config/locales/fr.yml | 1 + config/locales/gl.yml | 1 + config/locales/he.yml | 1 + config/locales/hu.yml | 1 + config/locales/it.yml | 1 + config/locales/ja.yml | 1 + config/locales/ko.yml | 1 + config/locales/lt.yml | 1 + config/locales/nl.yml | 1 + config/locales/no.yml | 1 + config/locales/pl.yml | 1 + config/locales/pt-BR.yml | 1 + config/locales/pt.yml | 1 + config/locales/ro.yml | 1 + config/locales/ru.yml | 1 + config/locales/sk.yml | 1 + config/locales/sl.yml | 1 + config/locales/sr.yml | 1 + config/locales/sv.yml | 1 + config/locales/th.yml | 1 + config/locales/tr.yml | 1 + config/locales/uk.yml | 1 + config/locales/vi.yml | 1 + config/locales/zh-TW.yml | 1 + config/locales/zh.yml | 1 + config/settings.yml | 5 +++++ test/functional/attachments_controller_test.rb | 11 +++++++++++ 37 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index c55e8de25..8c6346a5d 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -26,7 +26,7 @@ class AttachmentsController < ApplicationController if @attachment.is_diff? @diff = File.new(@attachment.diskfile, "rb").read render :action => 'diff' - elsif @attachment.is_text? + elsif @attachment.is_text? && @attachment.filesize <= Setting.setting_file_max_size_displayed.to_i.kilobyte @content = File.new(@attachment.diskfile, "rb").read render :action => 'file' else diff --git a/app/views/settings/_general.rhtml b/app/views/settings/_general.rhtml index e78667154..b6e570ba4 100644 --- a/app/views/settings/_general.rhtml +++ b/app/views/settings/_general.rhtml @@ -33,6 +33,9 @@

<%= text_field_tag 'settings[feeds_limit]', Setting.feeds_limit, :size => 6 %>

+

+<%= text_field_tag 'settings[setting_file_max_size_displayed]', Setting.setting_file_max_size_displayed, :size => 6 %> KB

+

<%= text_field_tag 'settings[diff_max_lines_displayed]', Setting.diff_max_lines_displayed, :size => 6 %>

diff --git a/config/locales/bg.yml b/config/locales/bg.yml index bf26c7d86..8431a204b 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -771,3 +771,4 @@ bg: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/ca.yml b/config/locales/ca.yml index cafda5945..ff77ce48a 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -772,3 +772,4 @@ ca: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 20a23a602..acd3faf37 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -776,3 +776,4 @@ cs: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/da.yml b/config/locales/da.yml index 5f109d49b..e38295111 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -803,3 +803,4 @@ da: general_csv_decimal_separator: '.' permission_edit_own_time_entries: Edit own time logs setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/de.yml b/config/locales/de.yml index 19b14149b..746ba965a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -804,3 +804,4 @@ de: button_create_and_continue: Create and continue text_custom_field_possible_values_info: 'One line for each value' setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/en.yml b/config/locales/en.yml index 8e47c991c..0f78ae1b3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -278,6 +278,7 @@ en: setting_sequential_project_identifiers: Generate sequential project identifiers setting_gravatar_enabled: Use Gravatar user icons setting_diff_max_lines_displayed: Max number of diff lines displayed + setting_file_max_size_displayed: Max size of text files displayed inline setting_repository_log_display_limit: Maximum number of revisions displayed on file log permission_edit_project: Edit project diff --git a/config/locales/es.yml b/config/locales/es.yml index 057ea5087..3c2c4cb0f 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -824,3 +824,4 @@ es: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 5375b641d..0b77144ac 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -814,3 +814,4 @@ fi: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/fr.yml b/config/locales/fr.yml index f3171e4e7..72d3baba3 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -311,6 +311,7 @@ fr: setting_sequential_project_identifiers: Générer des identifiants de projet séquentiels setting_gravatar_enabled: Afficher les Gravatar des utilisateurs setting_diff_max_lines_displayed: Nombre maximum de lignes de diff affichées + setting_file_max_size_displayed: Taille maximum des fichiers texte affichés en ligne setting_repository_log_display_limit: "Nombre maximum de revisions affichées sur l'historique d'un fichier" permission_edit_project: Modifier le projet diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 084852bed..7547f061e 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -804,3 +804,4 @@ gl: button_create_and_continue: Create and continue text_custom_field_possible_values_info: 'One line for each value' setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/he.yml b/config/locales/he.yml index 92d27904b..d31792683 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -787,3 +787,4 @@ he: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 32da62ecc..cf909e233 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -809,3 +809,4 @@ label_display: Megmutat field_editable: Szerkeszthető setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/it.yml b/config/locales/it.yml index 62670bc13..4f40d631b 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -790,3 +790,4 @@ it: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 84cfb58ba..0912746eb 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -802,3 +802,4 @@ ja: label_display: 表示 field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 03bfd17e8..e712b9206 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -833,3 +833,4 @@ ko: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 51989f971..9ebae4137 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -814,3 +814,4 @@ lt: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 09c0f84ce..941018be0 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -759,3 +759,4 @@ nl: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/no.yml b/config/locales/no.yml index 75202a864..a3cefa4b0 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -777,3 +777,4 @@ label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/pl.yml b/config/locales/pl.yml index b35df0377..f6c7d5088 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -807,3 +807,4 @@ pl: button_create_and_continue: Create and continue text_custom_field_possible_values_info: 'One line for each value' setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index d1b128466..05d1f271d 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -810,3 +810,4 @@ pt-BR: label_display: Exibição field_editable: Editável setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 387c0c768..c129fc199 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -795,3 +795,4 @@ pt: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/ro.yml b/config/locales/ro.yml index 102081d2b..e12ffa464 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -817,3 +817,4 @@ ro: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/ru.yml b/config/locales/ru.yml index c4b298484..0cbbda690 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -902,3 +902,4 @@ ru: field_editable: Редактируемый setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 7764e242d..8b95c6550 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -775,3 +775,4 @@ sk: button_create_and_continue: Create and continue text_custom_field_possible_values_info: 'One line for each value' setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 181d0df18..efb3a0314 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -773,3 +773,4 @@ sl: button_create_and_continue: Create and continue text_custom_field_possible_values_info: 'One line for each value' setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/sr.yml b/config/locales/sr.yml index 984b7e72d..235bb3fef 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -798,3 +798,4 @@ label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/sv.yml b/config/locales/sv.yml index e2ef8361e..050ba81ba 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -831,3 +831,4 @@ sv: enumeration_doc_categories: Dokumentkategorier enumeration_activities: Aktiviteter (tidsuppföljning) setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/th.yml b/config/locales/th.yml index 043de7b2a..a997b27b3 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -774,3 +774,4 @@ th: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 989113887..5bc612ac5 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -811,3 +811,4 @@ tr: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/uk.yml b/config/locales/uk.yml index 40e1d5c16..dd03860d5 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -773,3 +773,4 @@ uk: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/vi.yml b/config/locales/vi.yml index d110c5ed3..3a5389688 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -843,3 +843,4 @@ vi: label_display: Display field_editable: Editable setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 070efb4f1..160dc95ab 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -805,3 +805,4 @@ enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (時間追蹤) setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 5eaf2cb98..6bc0d788d 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -805,3 +805,4 @@ zh: enumeration_doc_categories: 文档类别 enumeration_activities: 活动(时间跟踪) setting_repository_log_display_limit: Maximum number of revisions displayed on file log + setting_file_max_size_displayed: Max size of text files displayed inline diff --git a/config/settings.yml b/config/settings.yml index 73b4c4cfb..fad3ef5fb 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -61,6 +61,11 @@ protocol: feeds_limit: format: int default: 15 +# Maximum size of files that can be displayed +# inline through the file viewer (in KB) +setting_file_max_size_displayed: + format: int + default: 512 diff_max_lines_displayed: format: int default: 1500 diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 43650bdfd..0639de8d9 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -53,12 +53,23 @@ class AttachmentsControllerTest < Test::Unit::TestCase get :show, :id => 5 assert_response :success assert_template 'diff' + assert_equal 'text/html', @response.content_type end def test_show_text_file get :show, :id => 4 assert_response :success assert_template 'file' + assert_equal 'text/html', @response.content_type + end + + def test_show_text_file_should_send_if_too_big + Setting.setting_file_max_size_displayed = 512 + Attachment.find(4).update_attribute :filesize, 754.kilobyte + + get :show, :id => 4 + assert_response :success + assert_equal 'application/x-ruby', @response.content_type end def test_show_other