diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index c55e8de2..8c6346a5 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 e7866715..b6e570ba 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 bf26c7d8..8431a204 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 cafda594..ff77ce48 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 20a23a60..acd3faf3 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 5f109d49..e3829511 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 19b14149..746ba965 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 8e47c991..0f78ae1b 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 057ea508..3c2c4cb0 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 5375b641..0b77144a 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 f3171e4e..72d3baba 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 084852be..7547f061 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 92d27904..d3179268 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 32da62ec..cf909e23 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 62670bc1..4f40d631 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 84cfb58b..0912746e 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 03bfd17e..e712b920 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 51989f97..9ebae413 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 09c0f84c..941018be 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 75202a86..a3cefa4b 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 b35df037..f6c7d508 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 d1b12846..05d1f271 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 387c0c76..c129fc19 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 102081d2..e12ffa46 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 c4b29848..0cbbda69 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 7764e242..8b95c655 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 181d0df1..efb3a031 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 984b7e72..235bb3fe 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 e2ef8361..050ba81b 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 043de7b2..a997b27b 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 98911388..5bc612ac 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 40e1d5c1..dd03860d 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 d110c5ed..3a538968 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 070efb4f..160dc95a 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 5eaf2cb9..6bc0d788 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 73b4c4cf..fad3ef5f 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 43650bdf..0639de8d 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