]> source.dussan.org Git - redmine.git/commitdiff
Add configurable setting for copying attachments when copying an issue (#36197).
authorGo MAEDA <maeda@farend.jp>
Sun, 14 Jul 2024 01:49:53 +0000 (01:49 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 14 Jul 2024 01:49:53 +0000 (01:49 +0000)
Patch by Yuichi HARADA (user:yui.har).

git-svn-id: https://svn.redmine.org/redmine/trunk@22926 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/helpers/settings_helper.rb
app/views/issues/new.html.erb
app/views/settings/_issues.html.erb
config/locales/en.yml
config/settings.yml
test/functional/issues_controller_test.rb

index 089da28a733cba4d34e42b6189032f0ea133a642..c5af8658f67878a1cd7c87a3b9d3950a34c3d210 100644 (file)
@@ -328,7 +328,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_on_issue_copy == 'ask')
       @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
       @watchers_present = User.current.allowed_to?(:add_issue_watchers, @projects) &&
                             Watcher.where(:watchable_type => 'Issue',
@@ -347,7 +348,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
@@ -386,7 +386,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])
@@ -593,7 +593,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,
@@ -696,6 +696,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_on_issue_copy
+    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]
index 77abaf2e3954c408686b0c8213310ae7ad286b3e..1fb57b2d7612ab1e75a5c80ab10064d35994eb3a 100644 (file)
@@ -166,6 +166,16 @@ module SettingsHelper
     options.map {|label, value| [l(label), value.to_s]}
   end
 
+  def copy_attachments_on_issue_copy_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
index 92f6f251a0ed3fc15cc50dae778a1358ee878fa6..40089215ca1955f8963b949565f6580f93d250fe 100644 (file)
@@ -17,7 +17,7 @@
       <%= check_box_tag 'link_copy', '1', @link_copy %>
     </p>
     <% end %>
-    <% if @copy_from && @copy_from.attachments.any? %>
+    <% if @copy_from && Setting.copy_attachments_on_issue_copy == 'ask' && @copy_from.attachments.any? %>
     <p>
       <label for="copy_attachments"><%= l(:label_copy_attachments) %></label>
       <%= check_box_tag 'copy_attachments', '1', @copy_attachments %>
index 7532d5d0e1b8b33a1e57050e2f01d64bc90cb9ba..0e978fa6b52e268cb2aa362bb136ed1fd4c73a16 100644 (file)
@@ -5,6 +5,8 @@
 
 <p><%= setting_select :link_copied_issue, link_copied_issue_options %></p>
 
+<p><%= setting_select :copy_attachments_on_issue_copy, copy_attachments_on_issue_copy_options %></p>
+
 <p><%= setting_select :cross_project_subtasks, cross_project_subtasks_options %></p>
 
 <p><%= setting_check_box :close_duplicate_issues %></p>
index 05e01b77a74449097a061ac322e89ee710a13c45..7d51ed1b70df69530ebda27f29e02def34613e40 100644 (file)
@@ -503,6 +503,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_on_issue_copy: 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
index 346288a4a2afc37daea52dc92c5e92df39a67957..19d3a33c7e991be7c958697d09b25a62ff0ba0f8 100644 (file)
@@ -190,6 +190,8 @@ parent_issue_done_ratio:
   default: 'derived'
 link_copied_issue:
   default: 'ask'
+copy_attachments_on_issue_copy:
+  default: 'ask'
 close_duplicate_issues:
   default: 1
 issue_group_assignment:
index 44ad19f224ec42abc5ca6ad1a4835623f4940825..3b7521d407f221d34b7b0dca1fa9e4030d594cd1 100644 (file)
@@ -5624,6 +5624,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_on_issue_copy => '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_on_issue_copy => '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!
@@ -8085,6 +8126,47 @@ class IssuesControllerTest < Redmine::ControllerTest
     end
   end
 
+  def test_bulk_copy_should_never_copy_attachments_by_settings
+    with_settings :copy_attachments_on_issue_copy => '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_on_issue_copy => '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