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
This commit is contained in:
Jean-Philippe Lang 2009-02-21 15:34:11 +00:00
parent 2bd419f23b
commit 66afc8c054
37 changed files with 53 additions and 1 deletions

View File

@ -26,7 +26,7 @@ class AttachmentsController < ApplicationController
if @attachment.is_diff? if @attachment.is_diff?
@diff = File.new(@attachment.diskfile, "rb").read @diff = File.new(@attachment.diskfile, "rb").read
render :action => 'diff' 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 @content = File.new(@attachment.diskfile, "rb").read
render :action => 'file' render :action => 'file'
else else

View File

@ -33,6 +33,9 @@
<p><label><%= l(:setting_feeds_limit) %></label> <p><label><%= l(:setting_feeds_limit) %></label>
<%= text_field_tag 'settings[feeds_limit]', Setting.feeds_limit, :size => 6 %></p> <%= text_field_tag 'settings[feeds_limit]', Setting.feeds_limit, :size => 6 %></p>
<p><label><%= l(:setting_file_max_size_displayed) %></label>
<%= text_field_tag 'settings[setting_file_max_size_displayed]', Setting.setting_file_max_size_displayed, :size => 6 %> KB</p>
<p><label><%= l(:setting_diff_max_lines_displayed) %></label> <p><label><%= l(:setting_diff_max_lines_displayed) %></label>
<%= text_field_tag 'settings[diff_max_lines_displayed]', Setting.diff_max_lines_displayed, :size => 6 %></p> <%= text_field_tag 'settings[diff_max_lines_displayed]', Setting.diff_max_lines_displayed, :size => 6 %></p>
</div> </div>

View File

@ -771,3 +771,4 @@ bg:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -772,3 +772,4 @@ ca:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -776,3 +776,4 @@ cs:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -803,3 +803,4 @@ da:
general_csv_decimal_separator: '.' general_csv_decimal_separator: '.'
permission_edit_own_time_entries: Edit own time logs permission_edit_own_time_entries: Edit own time logs
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -804,3 +804,4 @@ de:
button_create_and_continue: Create and continue button_create_and_continue: Create and continue
text_custom_field_possible_values_info: 'One line for each value' 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_repository_log_display_limit: Maximum number of revisions displayed on file log
setting_file_max_size_displayed: Max size of text files displayed inline

View File

@ -278,6 +278,7 @@ en:
setting_sequential_project_identifiers: Generate sequential project identifiers setting_sequential_project_identifiers: Generate sequential project identifiers
setting_gravatar_enabled: Use Gravatar user icons setting_gravatar_enabled: Use Gravatar user icons
setting_diff_max_lines_displayed: Max number of diff lines displayed 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 setting_repository_log_display_limit: Maximum number of revisions displayed on file log
permission_edit_project: Edit project permission_edit_project: Edit project

View File

@ -824,3 +824,4 @@ es:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -814,3 +814,4 @@ fi:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -311,6 +311,7 @@ fr:
setting_sequential_project_identifiers: Générer des identifiants de projet séquentiels setting_sequential_project_identifiers: Générer des identifiants de projet séquentiels
setting_gravatar_enabled: Afficher les Gravatar des utilisateurs setting_gravatar_enabled: Afficher les Gravatar des utilisateurs
setting_diff_max_lines_displayed: Nombre maximum de lignes de diff affichées 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" setting_repository_log_display_limit: "Nombre maximum de revisions affichées sur l'historique d'un fichier"
permission_edit_project: Modifier le projet permission_edit_project: Modifier le projet

View File

@ -804,3 +804,4 @@ gl:
button_create_and_continue: Create and continue button_create_and_continue: Create and continue
text_custom_field_possible_values_info: 'One line for each value' 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_repository_log_display_limit: Maximum number of revisions displayed on file log
setting_file_max_size_displayed: Max size of text files displayed inline

View File

@ -787,3 +787,4 @@ he:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -809,3 +809,4 @@
label_display: Megmutat label_display: Megmutat
field_editable: Szerkeszthető field_editable: Szerkeszthető
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -790,3 +790,4 @@ it:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -802,3 +802,4 @@ ja:
label_display: 表示 label_display: 表示
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -833,3 +833,4 @@ ko:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -814,3 +814,4 @@ lt:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -759,3 +759,4 @@ nl:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -777,3 +777,4 @@
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -807,3 +807,4 @@ pl:
button_create_and_continue: Create and continue button_create_and_continue: Create and continue
text_custom_field_possible_values_info: 'One line for each value' 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_repository_log_display_limit: Maximum number of revisions displayed on file log
setting_file_max_size_displayed: Max size of text files displayed inline

View File

@ -810,3 +810,4 @@ pt-BR:
label_display: Exibição label_display: Exibição
field_editable: Editável field_editable: Editável
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -795,3 +795,4 @@ pt:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -817,3 +817,4 @@ ro:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -902,3 +902,4 @@ ru:
field_editable: Редактируемый field_editable: Редактируемый
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -775,3 +775,4 @@ sk:
button_create_and_continue: Create and continue button_create_and_continue: Create and continue
text_custom_field_possible_values_info: 'One line for each value' 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_repository_log_display_limit: Maximum number of revisions displayed on file log
setting_file_max_size_displayed: Max size of text files displayed inline

View File

@ -773,3 +773,4 @@ sl:
button_create_and_continue: Create and continue button_create_and_continue: Create and continue
text_custom_field_possible_values_info: 'One line for each value' 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_repository_log_display_limit: Maximum number of revisions displayed on file log
setting_file_max_size_displayed: Max size of text files displayed inline

View File

@ -798,3 +798,4 @@
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -831,3 +831,4 @@ sv:
enumeration_doc_categories: Dokumentkategorier enumeration_doc_categories: Dokumentkategorier
enumeration_activities: Aktiviteter (tidsuppföljning) enumeration_activities: Aktiviteter (tidsuppföljning)
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -774,3 +774,4 @@ th:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -811,3 +811,4 @@ tr:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -773,3 +773,4 @@ uk:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -843,3 +843,4 @@ vi:
label_display: Display label_display: Display
field_editable: Editable field_editable: Editable
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -805,3 +805,4 @@
enumeration_doc_categories: 文件分類 enumeration_doc_categories: 文件分類
enumeration_activities: 活動 (時間追蹤) enumeration_activities: 活動 (時間追蹤)
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -805,3 +805,4 @@ zh:
enumeration_doc_categories: 文档类别 enumeration_doc_categories: 文档类别
enumeration_activities: 活动(时间跟踪) enumeration_activities: 活动(时间跟踪)
setting_repository_log_display_limit: Maximum number of revisions displayed on file log 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

View File

@ -61,6 +61,11 @@ protocol:
feeds_limit: feeds_limit:
format: int format: int
default: 15 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: diff_max_lines_displayed:
format: int format: int
default: 1500 default: 1500

View File

@ -53,12 +53,23 @@ class AttachmentsControllerTest < Test::Unit::TestCase
get :show, :id => 5 get :show, :id => 5
assert_response :success assert_response :success
assert_template 'diff' assert_template 'diff'
assert_equal 'text/html', @response.content_type
end end
def test_show_text_file def test_show_text_file
get :show, :id => 4 get :show, :id => 4
assert_response :success assert_response :success
assert_template 'file' 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 end
def test_show_other def test_show_other