Project

General

Profile

Feature #36197 » 36197.patch

Yuichi HARADA, 2021-11-22 06:51

View differences:

app/controllers/issues_controller.rb
317 317
    @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
318 318
    @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
319 319
    if @copy
320
      @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
320
      @attachments_present = @issues.detect {|i| i.attachments.any?}.present? &&
321
                               (Setting.copy_attachments_issue == 'ask')
321 322
      @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
322 323
      @watchers_present = User.current.allowed_to?(:add_issue_watchers, @projects) &&
323 324
                            Watcher.where(:watchable_type => 'Issue',
......
336 337

  
337 338
    attributes = parse_params_for_bulk_update(params[:issue])
338 339
    copy_subtasks = (params[:copy_subtasks] == '1')
339
    copy_attachments = (params[:copy_attachments] == '1')
340 340
    copy_watchers = (params[:copy_watchers] == '1')
341 341

  
342 342
    if @copy
......
375 375
      if @copy
376 376
        issue = orig_issue.copy(
377 377
          {},
378
          :attachments => copy_attachments,
378
          :attachments => copy_attachments?(params[:copy_attachments]),
379 379
          :subtasks => copy_subtasks,
380 380
          :watchers => copy_watchers,
381 381
          :link => link_copy?(params[:link_copy])
......
581 581
        end
582 582

  
583 583
        @link_copy = link_copy?(params[:link_copy]) || request.get?
584
        @copy_attachments = params[:copy_attachments].present? || request.get?
584
        @copy_attachments = copy_attachments?(params[:copy_attachments]) || request.get?
585 585
        @copy_subtasks = params[:copy_subtasks].present? || request.get?
586 586
        @copy_watchers = User.current.allowed_to?(:add_issue_watchers, @project)
587 587
        @issue.copy_from(@copy_from, :attachments => @copy_attachments,
......
684 684
    end
685 685
  end
686 686

  
687
  # Returns true if the attachments should be copied
688
  # from the original issue
689
  def copy_attachments?(param)
690
    case Setting.copy_attachments_issue
691
    when 'yes'
692
      true
693
    when 'no'
694
      false
695
    when 'ask'
696
      param == '1'
697
    end
698
  end
699

  
687 700
  # Redirects user after a successful issue creation
688 701
  def redirect_after_create
689 702
    if params[:continue]
app/helpers/settings_helper.rb
166 166
    options.map {|label, value| [l(label), value.to_s]}
167 167
  end
168 168

  
169
  def copy_attachments_issue_options
170
    options = [
171
      [:general_text_Yes, 'yes'],
172
      [:general_text_No, 'no'],
173
      [:label_ask, 'ask']
174
    ]
175

  
176
    options.map {|label, value| [l(label), value.to_s]}
177
  end
178

  
169 179
  def default_global_issue_query_options
170 180
    [[l(:label_none), '']] + IssueQuery.only_public.where(project_id: nil).pluck(:name, :id)
171 181
  end
app/views/issues/new.html.erb
17 17
      <%= check_box_tag 'link_copy', '1', @link_copy %>
18 18
    </p>
19 19
    <% end %>
20
    <% if @copy_from && @copy_from.attachments.any? %>
20
    <% if @copy_from && Setting.copy_attachments_issue == 'ask' && @copy_from.attachments.any? %>
21 21
    <p>
22 22
      <label for="copy_attachments"><%= l(:label_copy_attachments) %></label>
23 23
      <%= check_box_tag 'copy_attachments', '1', @copy_attachments %>
app/views/settings/_issues.html.erb
5 5

  
6 6
<p><%= setting_select :link_copied_issue, link_copied_issue_options %></p>
7 7

  
8
<p><%= setting_select :copy_attachments_issue, copy_attachments_issue_options %></p>
9

  
8 10
<p><%= setting_select :cross_project_subtasks, cross_project_subtasks_options %></p>
9 11

  
10 12
<p><%= setting_check_box :close_duplicate_issues %></p>
config/locales/en.yml
493 493
  setting_force_default_language_for_anonymous: Force default language for anonymous users
494 494
  setting_force_default_language_for_loggedin: Force default language for logged-in users
495 495
  setting_link_copied_issue: Link issues on copy
496
  setting_copy_attachments_issue: Copy attachments on copy
496 497
  setting_max_additional_emails: Maximum number of additional email addresses
497 498
  setting_email_domains_allowed: Allowed email domains
498 499
  setting_email_domains_denied: Disallowed email domains
......
1054 1055
  label_edit_attachments: Edit attached files
1055 1056
  label_download_all_attachments: Download all files
1056 1057
  label_link_copied_issue: Link copied issue
1058
  label_copy_attachments_issue: Attachment copied issue
1057 1059
  label_ask: Ask
1058 1060
  label_search_attachments_yes: Search attachment filenames and descriptions
1059 1061
  label_search_attachments_no: Do not search attachments
config/settings.yml
187 187
  default: 'derived'
188 188
link_copied_issue:
189 189
  default: 'ask'
190
copy_attachments_issue:
191
  default: 'ask'
190 192
close_duplicate_issues:
191 193
  default: 1
192 194
issue_group_assignment:
test/functional/issues_controller_test.rb
5414 5414
    end
5415 5415
  end
5416 5416

  
5417
  def test_create_as_copy_should_always_copy_attachments_by_settings
5418
    assert_equal 4, Issue.find(3).attachments.size
5419
    with_settings :copy_attachments_issue => 'yes' do
5420
      @request.session[:user_id] = 2
5421
      assert_difference 'Issue.count' do
5422
        assert_difference 'Attachment.count', 4 do
5423
          post(
5424
            :create,
5425
            :params => {
5426
              :project_id => 1,
5427
              :copy_from => 3,
5428
              :issue => {
5429
                :subject => 'Copy'
5430
              }
5431
            }
5432
          )
5433
        end
5434
      end
5435
    end
5436
  end
5437

  
5438
  def test_create_as_copy_should_never_copy_attachments_by_settings
5439
    with_settings :copy_attachments_issue => 'no' do
5440
      @request.session[:user_id] = 2
5441
      assert_difference 'Issue.count' do
5442
        assert_no_difference 'Attachment.count' do
5443
          post(
5444
            :create,
5445
            :params => {
5446
              :project_id => 1,
5447
              :copy_from => 3,
5448
              :issue => {
5449
                :subject => 'Copy'
5450
              }
5451
            }
5452
          )
5453
        end
5454
      end
5455
    end
5456
  end
5457

  
5417 5458
  def test_create_as_copy_should_copy_subtasks
5418 5459
    @request.session[:user_id] = 2
5419 5460
    issue = Issue.generate_with_descendants!
......
7855 7896
    end
7856 7897
  end
7857 7898

  
7899
  def test_bulk_copy_should_never_copy_attachments_by_settings
7900
    with_settings :copy_attachments_issue => 'no' do
7901
      @request.session[:user_id] = 2
7902
      assert_difference 'Issue.count' do
7903
        assert_no_difference 'Attachment.count' do
7904
          post(
7905
            :bulk_update,
7906
            :params => {
7907
              :ids => [3],
7908
              :copy => '1',
7909
              :issue => {
7910
                :project_id => ''
7911
              }
7912
            }
7913
          )
7914
        end
7915
      end
7916
    end
7917
  end
7918

  
7919
  def test_bulk_copy_should_always_copy_attachments_by_settings
7920
    assert_equal 4, Issue.find(3).attachments.size
7921
    with_settings :copy_attachments_issue => 'yes' do
7922
      @request.session[:user_id] = 2
7923
      assert_difference 'Issue.count' do
7924
        assert_difference 'Attachment.count', 4 do
7925
          post(
7926
            :bulk_update,
7927
            :params => {
7928
              :ids => [3],
7929
              :copy => '1',
7930
              :issue => {
7931
                :project_id => ''
7932
              }
7933
            }
7934
          )
7935
        end
7936
      end
7937
    end
7938
  end
7939

  
7858 7940
  def test_bulk_copy_should_add_relations_with_copied_issues
7859 7941
    @request.session[:user_id] = 2
7860 7942
    assert_difference 'Issue.count', 2 do
(2-2/3)