Project

General

Profile

Feature #18556 » 0001-Raise-the-maximum-number-of-files-that-can-be-attach.patch

Go MAEDA, 2026-09-24 12:58

View differences:

app/assets/javascripts/attachments.js
9 9
  var attachmentsFields = attachmentsForm.find('.attachments_fields');
10 10
  var attachmentsIcons = attachmentsForm.find('.attachments_icons');
11 11
  var addAttachment = attachmentsForm.find('.add_attachment');
12
  var maxFiles = ($(inputEl).attr('multiple') == 'multiple' ? 10 : 1);
12
  var maxFiles = $(inputEl).data('max-number-of-files');
13 13
  var delIcon = attachmentsIcons.find('svg.svg-del').clone();
14 14
  var attachmentIcon = attachmentsIcons.find('svg.svg-attachment').clone();
......
185 185
    $.each(files, function() {addFile(inputEl, this, true);});
186 186
  }
187
  if (filesLength > ($(inputEl).attr('multiple') == 'multiple' ? 10 : 1)) {
187
  if (filesLength > $(inputEl).data('max-number-of-files')) {
188 188
    window.alert($(inputEl).data('max-number-of-files-message'));
189 189
  }
190 190
  return sizeExceeded;
app/views/attachments/_form.html.erb
3 3
<% saved_attachments ||= container.saved_attachments if defined?(container) && container %>
4 4
<% multiple = true unless defined?(multiple) && multiple == false %>
5 5
<% show_add = multiple || saved_attachments.blank? %>
6
<% max_number_of_files = multiple ? Redmine::Configuration['max_attachments_at_once'].to_i : 1 %>
6 7
<% description = (defined?(description) && description == false ? false : true) %>
7 8
<% css_class = (defined?(filedrop) && filedrop == false ? '' : (attachment_format_custom_field ? 'custom-field-filedrop' : 'filedrop')) %>
......
38 39
        :multiple => multiple,
39 40
        :onchange => 'addInputFiles(this);',
40 41
        :data => {
41
          :max_number_of_files_message => l(:error_attachments_too_many, :max_number_of_files => (multiple ? 10 : 1)),
42
          :max_number_of_files => max_number_of_files,
43
          :max_number_of_files_message => l(:error_attachments_too_many, :max_number_of_files => max_number_of_files),
42 44
          :max_file_size => Setting.attachment_max_size.to_i.kilobytes,
43 45
          :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
44 46
          :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
config/configuration.yml.example
208 208
  # Maximum number of simultaneous AJAX uploads
209 209
  #max_concurrent_ajax_uploads: 2
210
  # Maximum number of files that can be attached at once with the
211
  # attachment form
212
  #
213
  # This limit is only applied in the browser, to keep the form usable when
214
  # many files are dropped by mistake. The number of attachments is not
215
  # limited by the server nor by the REST API.
216
  #max_attachments_at_once: 50
217

  
210 218
  # URL of the avatar server
211 219
  #
212 220
  # By default, Redmine uses Gravatar as the avatar server for displaying
lib/redmine/configuration.rb
26 26
      'avatar_server_url' => 'https://www.gravatar.com',
27 27
      'email_delivery' => nil,
28 28
      'max_concurrent_ajax_uploads' => 2,
29
      'max_attachments_at_once' => 50,
29 30
      'sudo_mode' => true,
30 31
      'common_mark_enable_hardbreaks' => true,
31 32
      'thumbnails_generation_timeout' => 10,
test/system/issues_test.rb
174 174
    assert_equal 'Some description', issue.attachments.first.description
175 175
  end
176
  def test_create_issue_should_not_attach_more_files_than_max_attachments_at_once
177
    set_tmp_attachments_directory
178
    log_user('jsmith', 'jsmith')
179

  
180
    Redmine::Configuration.with('max_attachments_at_once' => 3) do
181
      visit '/projects/ecookbook/issues/new'
182
    end
183
    files = %w(testfile.txt hello.pdf japanese-utf-8.txt iso8859-1.txt).map do |name|
184
      Rails.root.join('test/fixtures/files', name)
185
    end
186
    accept_alert(/maximum number of files that can be attached simultaneously \(3\)/) do
187
      attach_file 'attachments[dummy][file]', files
188
    end
189
    assert_selector '.attachments_fields > span', :count => 3
190
    assert_no_selector '.add_attachment', :visible => true
191
  end
192

  
176 193
  def test_create_issue_with_new_target_version
177 194
    log_user('jsmith', 'jsmith')
(5-5/5)