diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 78f7c27..ff04d05 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -273,7 +273,8 @@ class IssuesController < ApplicationController if @copy issue = orig_issue.copy({}, :attachments => params[:copy_attachments].present?, - :subtasks => params[:copy_subtasks].present? + :subtasks => params[:copy_subtasks].present?, + :link => link_copy?(params[:link_copy]) ) else issue = orig_issue @@ -410,9 +411,10 @@ class IssuesController < ApplicationController if params[:copy_from] begin @copy_from = Issue.visible.find(params[:copy_from]) + @link_copy = link_copy?(params[:link_copy]) || request.get? @copy_attachments = params[:copy_attachments].present? || request.get? @copy_subtasks = params[:copy_subtasks].present? || request.get? - @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks) + @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy) rescue ActiveRecord::RecordNotFound render_404 return @@ -486,4 +488,15 @@ class IssuesController < ApplicationController end end end + + def link_copy?(param) + case Setting.link_copied_issue + when 'yes' + true + when 'no' + false + when 'ask' + param == '1' + end + end end diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index 3e672b9..3183a2b 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -104,6 +104,16 @@ module SettingsHelper content_tag(:label, tag + text, options) end + def link_copied_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 cross_project_subtasks_options options = [ [:label_disabled, ''], diff --git a/app/views/issues/bulk_edit.html.erb b/app/views/issues/bulk_edit.html.erb index dfd7637..c16f48c 100644 --- a/app/views/issues/bulk_edit.html.erb +++ b/app/views/issues/bulk_edit.html.erb @@ -97,6 +97,14 @@
<% end %> +<% if @copy && Setting.link_copied_issue == 'ask' %> ++ + <%= hidden_field_tag 'link_copy', '0' %> + <%= check_box_tag 'link_copy', '1', params[:link_copy] != 0 %> +
+<% end %> + <% if @copy && @attachments_present %> <%= hidden_field_tag 'copy_attachments', '0' %>diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index 40dae18..206df8d 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -11,6 +11,12 @@ <%= render :partial => 'issues/form', :locals => {:f => f} %> + <% if @copy_from && Setting.link_copied_issue == 'ask' %> +
+ + <%= check_box_tag 'link_copy', '1', @link_copy %> +
+ <% end %> <% if @copy_from && @copy_from.attachments.any? %>diff --git a/app/views/settings/_issues.html.erb b/app/views/settings/_issues.html.erb index fac6d6d..c1e8022 100644 --- a/app/views/settings/_issues.html.erb +++ b/app/views/settings/_issues.html.erb @@ -3,6 +3,8 @@
<%= setting_check_box :cross_project_issue_relations %>
+<%= setting_select :link_copied_issue, link_copied_issue_options %>
+<%= setting_select :cross_project_subtasks, cross_project_subtasks_options %>
<%= setting_check_box :issue_group_assignment %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 7fdbc28..fa33cc9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -412,6 +412,7 @@ en: setting_mail_handler_excluded_filenames: Exclude attachments by name 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 permission_add_project: Create project permission_add_subprojects: Create subprojects @@ -924,6 +925,8 @@ en: label_users_visibility_all: All active users label_users_visibility_members_of_visible_projects: Members of visible projects label_edit_attachments: Edit attached files + label_link_copied_issue: Link copied issue + label_ask: Ask button_login: Login button_submit: Submit diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2e70ea2..a167fa0 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -432,6 +432,7 @@ fr: setting_mail_handler_excluded_filenames: Exclure les fichiers attachés par leur nom setting_force_default_language_for_anonymous: Forcer la langue par défault pour les utilisateurs anonymes setting_force_default_language_for_loggedin: Forcer la langue par défault pour les utilisateurs identifiés + setting_link_copied_issue: Lier les demandes lors de la copie permission_add_project: Créer un projet permission_add_subprojects: Créer des sous-projets @@ -944,6 +945,8 @@ fr: label_users_visibility_all: Tous les utilisateurs actifs label_users_visibility_members_of_visible_projects: Membres des projets visibles label_edit_attachments: Modifier les fichiers attachés + label_link_copied_issue: Lier la demande copiée + label_ask: Demander button_login: Connexion button_submit: Soumettre diff --git a/config/settings.yml b/config/settings.yml index d0c3018..bc4e750 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -136,6 +136,8 @@ cross_project_issue_relations: # Enables subtasks to be in other projects cross_project_subtasks: default: 'tree' +link_copied_issue: + default: 'ask' issue_group_assignment: default: 0 default_issue_start_date_to_creation_date: diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 1c3702c..06ac5b3 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -2540,12 +2540,10 @@ class IssuesControllerTest < ActionController::TestCase assert count > 0 assert_difference 'Issue.count' do assert_difference 'Attachment.count', count do - assert_difference 'Journal.count', 2 do - post :create, :project_id => 1, :copy_from => 3, - :issue => {:project_id => '1', :tracker_id => '3', - :status_id => '1', :subject => 'Copy with attachments'}, - :copy_attachments => '1' - end + post :create, :project_id => 1, :copy_from => 3, + :issue => {:project_id => '1', :tracker_id => '3', + :status_id => '1', :subject => 'Copy with attachments'}, + :copy_attachments => '1' end end copy = Issue.order('id DESC').first @@ -2560,33 +2558,29 @@ class IssuesControllerTest < ActionController::TestCase assert count > 0 assert_difference 'Issue.count' do assert_no_difference 'Attachment.count' do - assert_difference 'Journal.count', 2 do - post :create, :project_id => 1, :copy_from => 3, - :issue => {:project_id => '1', :tracker_id => '3', - :status_id => '1', :subject => 'Copy with attachments'} - end + post :create, :project_id => 1, :copy_from => 3, + :issue => {:project_id => '1', :tracker_id => '3', + :status_id => '1', :subject => 'Copy with attachments'} end end copy = Issue.order('id DESC').first assert_equal 0, copy.attachments.count end - def test_create_as_copy_with_attachments_should_add_new_files + def test_create_as_copy_with_attachments_should_also_add_new_files @request.session[:user_id] = 2 issue = Issue.find(3) count = issue.attachments.count assert count > 0 assert_difference 'Issue.count' do assert_difference 'Attachment.count', count + 1 do - assert_difference 'Journal.count', 2 do - post :create, :project_id => 1, :copy_from => 3, - :issue => {:project_id => '1', :tracker_id => '3', - :status_id => '1', :subject => 'Copy with attachments'}, - :copy_attachments => '1', - :attachments => {'1' => - {'file' => uploaded_test_file('testfile.txt', 'text/plain'), - 'description' => 'test file'}} - end + post :create, :project_id => 1, :copy_from => 3, + :issue => {:project_id => '1', :tracker_id => '3', + :status_id => '1', :subject => 'Copy with attachments'}, + :copy_attachments => '1', + :attachments => {'1' => + {'file' => uploaded_test_file('testfile.txt', 'text/plain'), + 'description' => 'test file'}} end end copy = Issue.order('id DESC').first @@ -2597,7 +2591,7 @@ class IssuesControllerTest < ActionController::TestCase @request.session[:user_id] = 2 assert_difference 'Issue.count' do assert_difference 'IssueRelation.count' do - post :create, :project_id => 1, :copy_from => 1, + post :create, :project_id => 1, :copy_from => 1, :link_copy => '1', :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} end @@ -2606,17 +2600,37 @@ class IssuesControllerTest < ActionController::TestCase assert_equal 1, copy.relations.size end + def test_create_as_copy_should_allow_not_to_add_relation_with_copied_issue + @request.session[:user_id] = 2 + assert_difference 'Issue.count' do + assert_no_difference 'IssueRelation.count' do + post :create, :project_id => 1, :copy_from => 1, + :issue => {:subject => 'Copy'} + end + end + end + + def test_create_as_copy_should_always_add_relation_with_copied_issue_by_setting + with_settings :link_copied_issue => 'yes' do + @request.session[:user_id] = 2 + assert_difference 'Issue.count' do + assert_difference 'IssueRelation.count' do + post :create, :project_id => 1, :copy_from => 1, + :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! count = issue.descendants.count assert_difference 'Issue.count', count + 1 do - assert_difference 'Journal.count', (count + 1) * 2 do - post :create, :project_id => 1, :copy_from => issue.id, - :issue => {:project_id => '1', :tracker_id => '3', - :status_id => '1', :subject => 'Copy with subtasks'}, - :copy_subtasks => '1' - end + post :create, :project_id => 1, :copy_from => issue.id, + :issue => {:project_id => '1', :tracker_id => '3', + :status_id => '1', :subject => 'Copy with subtasks'}, + :copy_subtasks => '1' end copy = Issue.where(:parent_id => nil).order('id DESC').first assert_equal count, copy.descendants.count @@ -2627,11 +2641,9 @@ class IssuesControllerTest < ActionController::TestCase @request.session[:user_id] = 2 issue = Issue.generate_with_descendants! assert_difference 'Issue.count', 1 do - assert_difference 'Journal.count', 2 do - post :create, :project_id => 1, :copy_from => 3, - :issue => {:project_id => '1', :tracker_id => '3', - :status_id => '1', :subject => 'Copy with subtasks'} - end + post :create, :project_id => 1, :copy_from => 3, + :issue => {:project_id => '1', :tracker_id => '3', + :status_id => '1', :subject => 'Copy with subtasks'} end copy = Issue.where(:parent_id => nil).order('id DESC').first assert_equal 0, copy.descendants.count @@ -3840,7 +3852,6 @@ class IssuesControllerTest < ActionController::TestCase issue = Issue.order('id DESC').first assert_equal 1, issue.journals.size journal = issue.journals.first - assert_equal 1, journal.details.size assert_equal 'Copying one issue', journal.notes end @@ -3879,7 +3890,7 @@ class IssuesControllerTest < ActionController::TestCase assert_difference 'Issue.count', 2 do assert_difference 'IssueRelation.count', 2 do - post :bulk_update, :ids => [1, 3], :copy => '1', + post :bulk_update, :ids => [1, 3], :copy => '1', :link_copy => '1', :issue => { :project_id => '1' }