diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index eca53d7f54..562e2d817b 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -317,7 +317,8 @@ class IssuesController < ApplicationController @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) if @copy - @attachments_present = @issues.detect {|i| i.attachments.any?}.present? + @attachments_present = @issues.detect {|i| i.attachments.any?}.present? && + (Setting.copy_attachments_issue == 'ask') @subtasks_present = @issues.detect {|i| !i.leaf?}.present? @watchers_present = User.current.allowed_to?(:add_issue_watchers, @projects) && Watcher.where(:watchable_type => 'Issue', @@ -336,7 +337,6 @@ class IssuesController < ApplicationController attributes = parse_params_for_bulk_update(params[:issue]) copy_subtasks = (params[:copy_subtasks] == '1') - copy_attachments = (params[:copy_attachments] == '1') copy_watchers = (params[:copy_watchers] == '1') if @copy @@ -375,7 +375,7 @@ class IssuesController < ApplicationController if @copy issue = orig_issue.copy( {}, - :attachments => copy_attachments, + :attachments => copy_attachments?(params[:copy_attachments]), :subtasks => copy_subtasks, :watchers => copy_watchers, :link => link_copy?(params[:link_copy]) @@ -581,7 +581,7 @@ class IssuesController < ApplicationController end @link_copy = link_copy?(params[:link_copy]) || request.get? - @copy_attachments = params[:copy_attachments].present? || request.get? + @copy_attachments = copy_attachments?(params[:copy_attachments]) || request.get? @copy_subtasks = params[:copy_subtasks].present? || request.get? @copy_watchers = User.current.allowed_to?(:add_issue_watchers, @project) @issue.copy_from(@copy_from, :attachments => @copy_attachments, @@ -684,6 +684,19 @@ class IssuesController < ApplicationController end end + # Returns true if the attachments should be copied + # from the original issue + def copy_attachments?(param) + case Setting.copy_attachments_issue + when 'yes' + true + when 'no' + false + when 'ask' + param == '1' + end + end + # Redirects user after a successful issue creation def redirect_after_create if params[:continue] diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index a6563a4fbc..646b83fc85 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -166,6 +166,16 @@ module SettingsHelper options.map {|label, value| [l(label), value.to_s]} end + def copy_attachments_issue_options + options = [ + [:general_text_Yes, 'yes'], + [:general_text_No, 'no'], + [:label_ask, 'ask'] + ] + + options.map {|label, value| [l(label), value.to_s]} + end + def default_global_issue_query_options [[l(:label_none), '']] + IssueQuery.only_public.where(project_id: nil).pluck(:name, :id) end diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index 92f6f251a0..ebf6466f05 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -17,7 +17,7 @@ <%= check_box_tag 'link_copy', '1', @link_copy %>
<% end %> - <% if @copy_from && @copy_from.attachments.any? %> + <% if @copy_from && Setting.copy_attachments_issue == 'ask' && @copy_from.attachments.any? %><%= check_box_tag 'copy_attachments', '1', @copy_attachments %> diff --git a/app/views/settings/_issues.html.erb b/app/views/settings/_issues.html.erb index 7109e906f4..a4972f1078 100644 --- a/app/views/settings/_issues.html.erb +++ b/app/views/settings/_issues.html.erb @@ -5,6 +5,8 @@
<%= setting_select :link_copied_issue, link_copied_issue_options %>
+<%= setting_select :copy_attachments_issue, copy_attachments_issue_options %>
+<%= setting_select :cross_project_subtasks, cross_project_subtasks_options %>
<%= setting_check_box :close_duplicate_issues %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 2eb4af0e13..feec9bb9af 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -493,6 +493,7 @@ en: setting_force_default_language_for_anonymous: Force default language for anonymous users setting_force_default_language_for_loggedin: Force default language for logged-in users setting_link_copied_issue: Link issues on copy + setting_copy_attachments_issue: Copy attachments on copy setting_max_additional_emails: Maximum number of additional email addresses setting_email_domains_allowed: Allowed email domains setting_email_domains_denied: Disallowed email domains @@ -1054,6 +1055,7 @@ en: label_edit_attachments: Edit attached files label_download_all_attachments: Download all files label_link_copied_issue: Link copied issue + label_copy_attachments_issue: Attachment copied issue label_ask: Ask label_search_attachments_yes: Search attachment filenames and descriptions label_search_attachments_no: Do not search attachments diff --git a/config/settings.yml b/config/settings.yml index 211d58087d..ebbf31fb6d 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -187,6 +187,8 @@ parent_issue_done_ratio: default: 'derived' link_copied_issue: default: 'ask' +copy_attachments_issue: + default: 'ask' close_duplicate_issues: default: 1 issue_group_assignment: diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 434775e59c..785b2810b3 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -5414,6 +5414,47 @@ class IssuesControllerTest < Redmine::ControllerTest end end + def test_create_as_copy_should_always_copy_attachments_by_settings + assert_equal 4, Issue.find(3).attachments.size + with_settings :copy_attachments_issue => 'yes' do + @request.session[:user_id] = 2 + assert_difference 'Issue.count' do + assert_difference 'Attachment.count', 4 do + post( + :create, + :params => { + :project_id => 1, + :copy_from => 3, + :issue => { + :subject => 'Copy' + } + } + ) + end + end + end + end + + def test_create_as_copy_should_never_copy_attachments_by_settings + with_settings :copy_attachments_issue => 'no' do + @request.session[:user_id] = 2 + assert_difference 'Issue.count' do + assert_no_difference 'Attachment.count' do + post( + :create, + :params => { + :project_id => 1, + :copy_from => 3, + :issue => { + :subject => 'Copy' + } + } + ) + end + end + end + end + def test_create_as_copy_should_copy_subtasks @request.session[:user_id] = 2 issue = Issue.generate_with_descendants! @@ -7855,6 +7896,47 @@ class IssuesControllerTest < Redmine::ControllerTest end end + def test_bulk_copy_should_never_copy_attachments_by_settings + with_settings :copy_attachments_issue => 'no' do + @request.session[:user_id] = 2 + assert_difference 'Issue.count' do + assert_no_difference 'Attachment.count' do + post( + :bulk_update, + :params => { + :ids => [3], + :copy => '1', + :issue => { + :project_id => '' + } + } + ) + end + end + end + end + + def test_bulk_copy_should_always_copy_attachments_by_settings + assert_equal 4, Issue.find(3).attachments.size + with_settings :copy_attachments_issue => 'yes' do + @request.session[:user_id] = 2 + assert_difference 'Issue.count' do + assert_difference 'Attachment.count', 4 do + post( + :bulk_update, + :params => { + :ids => [3], + :copy => '1', + :issue => { + :project_id => '' + } + } + ) + end + end + end + end + def test_bulk_copy_should_add_relations_with_copied_issues @request.session[:user_id] = 2 assert_difference 'Issue.count', 2 do