summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-01-01 12:09:09 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-01-01 12:09:09 +0000
commit6487c1803fa947f73c4667bb10f762a98487aa1b (patch)
treeb4fc8295773fff6bde8aa060d2a8536b4cffc3e0
parentff65a5b22a5441476320a461c986a64b84ee025a (diff)
downloadredmine-6487c1803fa947f73c4667bb10f762a98487aa1b.tar.gz
redmine-6487c1803fa947f73c4667bb10f762a98487aa1b.zip
option to set maximum size of uploaded files
git-svn-id: http://redmine.rubyforge.org/svn/trunk@131 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/attachment.rb6
-rw-r--r--app/views/documents/show.rhtml2
-rw-r--r--app/views/issues/show.rhtml2
-rw-r--r--app/views/projects/add_document.rhtml2
-rw-r--r--app/views/projects/add_file.rhtml2
-rw-r--r--app/views/projects/add_issue.rhtml2
-rw-r--r--config/config_custom.example.rb4
-rw-r--r--lang/de.yml1
-rw-r--r--lang/en.yml1
-rw-r--r--lang/es.yml1
-rw-r--r--lang/fr.yml1
11 files changed, 18 insertions, 6 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index aca86cec5..cdf5a3e47 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -21,8 +21,12 @@ class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
+ @@max_size = $RDM_ATTACHMENT_MAX_SIZE || 5*1024*1024
+ cattr_reader :max_size
+
validates_presence_of :container, :filename
-
+ validates_inclusion_of :filesize, :in => 1..@@max_size
+
def file=(incomming_file)
unless incomming_file.nil?
@temp_file = incomming_file
diff --git a/app/views/documents/show.rhtml b/app/views/documents/show.rhtml
index ace093dc5..923701dd2 100644
--- a/app/views/documents/show.rhtml
+++ b/app/views/documents/show.rhtml
@@ -31,7 +31,7 @@
<%= start_form_tag ({ :controller => 'documents', :action => 'add_attachment', :id => @document }, :multipart => true, :class => "tabular") %>
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label>
- <%= file_field_tag 'attachments[]', :size => 30 %></p>
+ <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>
<% end %>
diff --git a/app/views/issues/show.rhtml b/app/views/issues/show.rhtml
index 0d4bfa497..a6fb46604 100644
--- a/app/views/issues/show.rhtml
+++ b/app/views/issues/show.rhtml
@@ -89,7 +89,7 @@ end %>
<%= start_form_tag ({ :controller => 'issues', :action => 'add_attachment', :id => @issue }, :multipart => true, :class => "tabular") %>
<p id="attachments_p"><label><%=l(:label_attachment_new)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label>
- <%= file_field_tag 'attachments[]', :size => 30 %></p>
+ <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %>
<% end %>
diff --git a/app/views/projects/add_document.rhtml b/app/views/projects/add_document.rhtml
index e788a7bc7..37e0b7d60 100644
--- a/app/views/projects/add_document.rhtml
+++ b/app/views/projects/add_document.rhtml
@@ -6,7 +6,7 @@
<div class="box">
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label>
-<%= file_field_tag 'attachments[]', :size => 30 %></p>
+<%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
</div>
<%= submit_tag l(:button_create) %>
diff --git a/app/views/projects/add_file.rhtml b/app/views/projects/add_file.rhtml
index 41c208431..5ae6dde29 100644
--- a/app/views/projects/add_file.rhtml
+++ b/app/views/projects/add_file.rhtml
@@ -9,7 +9,7 @@
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label>
-<%= file_field_tag 'attachments[]', :size => 30 %></p>
+<%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
</div>
<%= submit_tag l(:button_add) %>
<%= end_form_tag %> \ No newline at end of file
diff --git a/app/views/projects/add_issue.rhtml b/app/views/projects/add_issue.rhtml
index b60f91a2e..dfd1b314e 100644
--- a/app/views/projects/add_issue.rhtml
+++ b/app/views/projects/add_issue.rhtml
@@ -27,7 +27,7 @@
<p id="attachments_p"><label for="attachment_file"><%=l(:label_attachment)%>&nbsp;
<%= link_to_function image_tag('add'), "addFileField()" %></label>
-<%= file_field_tag 'attachments[]', :size => 30 %></p>
+<%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= human_size(Attachment.max_size) %>)</em></p>
</div>
<!--[eoform:issue]-->
diff --git a/config/config_custom.example.rb b/config/config_custom.example.rb
index 689d9daec..b00e716b1 100644
--- a/config/config_custom.example.rb
+++ b/config/config_custom.example.rb
@@ -63,3 +63,7 @@
# Textile formatting is automativaly disabled if RedCloth is not available
# Set to true to manually disable.
# $RDM_TEXTILE_DISABLED = true
+
+# Maximum size for attachments (in bytes)
+# Default to 5 MB
+# $RDM_ATTACHMENT_MAX_SIZE = 5*1024*1024
diff --git a/lang/de.yml b/lang/de.yml
index 34fedc1ea..03bbe18c7 100644
--- a/lang/de.yml
+++ b/lang/de.yml
@@ -295,6 +295,7 @@ label_modified: geändert
label_deleted: gelöscht
label_latest_revision: Neueste Neuausgabe
label_view_revisions: Die Neuausgaben ansehen
+label_max_size: Maximale Größe
button_login: Einloggen
button_submit: Einreichen
diff --git a/lang/en.yml b/lang/en.yml
index b6734985a..d41457d6e 100644
--- a/lang/en.yml
+++ b/lang/en.yml
@@ -295,6 +295,7 @@ label_modified: modified
label_deleted: deleted
label_latest_revision: Latest revision
label_view_revisions: View revisions
+label_max_size: Maximum size
button_login: Login
button_submit: Submit
diff --git a/lang/es.yml b/lang/es.yml
index 7eb3fa9fd..73ae4cec5 100644
--- a/lang/es.yml
+++ b/lang/es.yml
@@ -295,6 +295,7 @@ label_modified: modificado
label_deleted: suprimido
label_latest_revision: La revisión más última
label_view_revisions: Ver las revisiones
+label_max_size: Tamaño máximo
button_login: Conexión
button_submit: Someter
diff --git a/lang/fr.yml b/lang/fr.yml
index 4b4b04925..e0e9d996f 100644
--- a/lang/fr.yml
+++ b/lang/fr.yml
@@ -296,6 +296,7 @@ label_modified: modifié
label_deleted: supprimé
label_latest_revision: Dernière révision
label_view_revisions: Voir les révisions
+label_max_size: Taille maximale
button_login: Connexion
button_submit: Soumettre