diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 82fa5f8ea..e3e6ffedc 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -360,11 +360,15 @@ private def build_new_issue_from_params if params[:id].blank? @issue = Issue.new - begin - @issue.copy_from(params[:copy_from]) if params[:copy_from] - rescue ActiveRecord::RecordNotFound - render_404 - return + if params[:copy_from] + begin + @copy_from = Issue.visible.find(params[:copy_from]) + @copy_attachments = params[:copy_attachments].present? || request.get? + @issue.copy_from(@copy_from, :attachments => @copy_attachments) + rescue ActiveRecord::RecordNotFound + render_404 + return + end end @issue.project = @project else diff --git a/app/models/issue.rb b/app/models/issue.rb index 16257bf83..ad91ab488 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -129,14 +129,16 @@ class Issue < ActiveRecord::Base end # Copies attributes from another issue, arg can be an id or an Issue - def copy_from(arg) + def copy_from(arg, options={}) issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg) self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on") self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h} self.status = issue.status self.author = User.current - self.attachments = issue.attachments.map do |attachement| - attachement.copy(:container => self) + unless options[:attachments] == false + self.attachments = issue.attachments.map do |attachement| + attachement.copy(:container => self) + end end @copied_from = issue self diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index 7ff994de5..bddb62788 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -11,6 +11,13 @@ <%= render :partial => 'issues/form', :locals => {:f => f} %> + <% if @copy_from && @copy_from.attachments.any? %> +
+ + <%= check_box_tag 'copy_attachments', '1', @copy_attachments %> +
+ <% end %> +<%= label_tag('attachments[1][file]', l(:label_attachment_plural))%><%= render :partial => 'attachments/form' %>
<% if @issue.safe_attribute? 'watcher_user_ids' -%> diff --git a/config/locales/ar.yml b/config/locales/ar.yml index cb8bc29ee..d35155043 100644 --- a/config/locales/ar.yml +++ b/config/locales/ar.yml @@ -1013,3 +1013,4 @@ ar: other: "%{count} قضايا" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/bg.yml b/config/locales/bg.yml index a7acdb2e7..c3614d254 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -1011,3 +1011,4 @@ bg: description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати description_date_from: Въведете начална дата description_date_to: Въведете крайна дата + label_copy_attachments: Copy attachments diff --git a/config/locales/bs.yml b/config/locales/bs.yml index d75873a68..d593bf7e6 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -1027,3 +1027,4 @@ bs: other: "%{count} aktivnosti" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 3a8455efe..b2f013a54 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -1015,3 +1015,4 @@ ca: other: "%{count} assumptes" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 858a65633..d358bd4e0 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -1016,3 +1016,4 @@ cs: other: "%{count} Úkoly" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/da.yml b/config/locales/da.yml index 9242e203b..fd93af67e 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -1030,3 +1030,4 @@ da: other: "%{count} sager" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/de.yml b/config/locales/de.yml index 1582454b0..ccb5d56a7 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1033,3 +1033,4 @@ de: other: "%{count} tickets" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/el.yml b/config/locales/el.yml index 29a6a938f..a5ea7becd 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -1013,3 +1013,4 @@ el: other: "%{count} Θέματα" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index fbf058282..0bd2cf138 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -1015,3 +1015,4 @@ en-GB: other: "%{count} issues" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/en.yml b/config/locales/en.yml index 6dc4cb3d7..091238385 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -836,6 +836,7 @@ en: label_parent_revision: Parent label_child_revision: Child label_export_options: "%{export_format} export options" + label_copy_attachments: Copy attachments button_login: Login button_submit: Submit diff --git a/config/locales/es.yml b/config/locales/es.yml index d9c53a72e..d4cf9af9d 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1050,3 +1050,4 @@ es: other: "%{count} peticiones" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/eu.yml b/config/locales/eu.yml index 3bf89efa2..8e2410906 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -1016,3 +1016,4 @@ eu: other: "%{count} zereginak" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/fa.yml b/config/locales/fa.yml index f02f33de9..b98fe1051 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -1015,3 +1015,4 @@ fa: other: "%{count} پیامد" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 4585fb9d4..4e3e9599a 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -1034,3 +1034,4 @@ fi: other: "%{count} tapahtumat" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 904c3a6c5..846648da7 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -812,6 +812,7 @@ fr: label_issues_visibility_public: Toutes les demandes non privées label_issues_visibility_own: Demandes créées par ou assignées à l'utilisateur label_export_options: Options d'exportation %{export_format} + label_copy_attachments: Copier les fichiers button_login: Connexion button_submit: Soumettre diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 3f28af4c7..a1c66556c 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -1024,3 +1024,4 @@ gl: other: "%{count} peticións" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/he.yml b/config/locales/he.yml index bb604c2f7..aaa5d340e 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -1018,3 +1018,4 @@ he: other: "%{count} נושאים" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/hr.yml b/config/locales/hr.yml index 78b33c10b..13e779d3a 100644 --- a/config/locales/hr.yml +++ b/config/locales/hr.yml @@ -1019,3 +1019,4 @@ hr: other: "%{count} predmeti" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 8c78d8a57..4f947f991 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -1032,3 +1032,4 @@ other: "%{count} feladatok" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/id.yml b/config/locales/id.yml index 3ba2bc5f6..c35586998 100644 --- a/config/locales/id.yml +++ b/config/locales/id.yml @@ -1019,3 +1019,4 @@ id: other: "%{count} masalah" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/it.yml b/config/locales/it.yml index eb6c804f3..74647fb2c 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -1014,3 +1014,4 @@ it: other: "%{count} segnalazioni" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 04d71e80f..0c7ebe1ba 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1043,3 +1043,4 @@ ja: other: "%{count} チケット" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/ko.yml b/config/locales/ko.yml index a78d505b9..6f58cb7a1 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -1065,3 +1065,4 @@ ko: other: "%{count} 일감" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 4ca8e1eb6..4e756118a 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -1073,3 +1073,4 @@ lt: other: "%{count} darbai" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/lv.yml b/config/locales/lv.yml index aefce5997..bcf2cc46f 100644 --- a/config/locales/lv.yml +++ b/config/locales/lv.yml @@ -1007,3 +1007,4 @@ lv: other: "%{count} uzdevumi" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/mk.yml b/config/locales/mk.yml index 477dc6b14..cde40e144 100644 --- a/config/locales/mk.yml +++ b/config/locales/mk.yml @@ -1013,3 +1013,4 @@ mk: other: "%{count} Задачи" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/mn.yml b/config/locales/mn.yml index 71cf161db..6c4dd0a41 100644 --- a/config/locales/mn.yml +++ b/config/locales/mn.yml @@ -1013,3 +1013,4 @@ mn: other: "%{count} Асуудлууд" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/nl.yml b/config/locales/nl.yml index c6fe47b14..bc2582a02 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -995,3 +995,4 @@ nl: other: "%{count} issues" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/no.yml b/config/locales/no.yml index 7ebb9224e..aedbc2acb 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -1003,3 +1003,4 @@ other: "%{count} saker" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/pl.yml b/config/locales/pl.yml index ec348566f..74678aa51 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -1030,3 +1030,4 @@ pl: other: "%{count} zagadnienia" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index fa266210e..3495a5242 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -1036,3 +1036,4 @@ pt-BR: other: "%{count} tarefas" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/pt.yml b/config/locales/pt.yml index e07a8041c..2af5cf733 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -1018,3 +1018,4 @@ pt: other: "%{count} tarefas" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/ro.yml b/config/locales/ro.yml index 918922618..69a739109 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -1005,3 +1005,4 @@ ro: other: "%{count} tichete" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/ru.yml b/config/locales/ru.yml index e386c7b56..545e50ca6 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -1126,3 +1126,4 @@ ru: other: "%{count} Задачи" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 7a939b433..5095d073d 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -1008,3 +1008,4 @@ sk: other: "%{count} Úlohy" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 81f43b105..f29657580 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -1013,3 +1013,4 @@ sl: other: "%{count} zahtevki" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/sr-YU.yml b/config/locales/sr-YU.yml index 348478521..cfddaeb57 100644 --- a/config/locales/sr-YU.yml +++ b/config/locales/sr-YU.yml @@ -1013,3 +1013,4 @@ sr-YU: other: "%{count} problemi" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/sr.yml b/config/locales/sr.yml index 3a0b1c3ac..5ec55d8a3 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -1014,3 +1014,4 @@ sr: other: "%{count} Проблеми" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 2408032fa..5a07696fe 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -1054,3 +1054,4 @@ sv: other: "%{count} Ärenden" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/th.yml b/config/locales/th.yml index 1bcaaa828..9ceec83b5 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -1010,3 +1010,4 @@ th: other: "%{count} ปัญหา" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 9343f9f46..ad7375646 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -1032,3 +1032,4 @@ tr: other: "%{count} İşler" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/uk.yml b/config/locales/uk.yml index df9a0ca56..97e6ae369 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -1010,3 +1010,4 @@ uk: other: "%{count} Питання" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/vi.yml b/config/locales/vi.yml index fb2bf76f8..2caf05e26 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -1064,3 +1064,4 @@ vi: other: "%{count} vấn đề" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index f098be1e7..95b7ba5db 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -1093,3 +1093,4 @@ other: "%{count} 問題清單" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 93e3ce4b3..c9503c561 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1015,3 +1015,4 @@ zh: other: "%{count} 问题" label_repository_new: New repository field_repository_is_default: Main repository + label_copy_attachments: Copy attachments diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 55c4cb932..7bc0d7119 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1631,6 +1631,24 @@ class IssuesControllerTest < ActionController::TestCase assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} end + def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox + @request.session[:user_id] = 2 + issue = Issue.find(3) + assert issue.attachments.count > 0 + get :new, :project_id => 1, :copy_from => 3 + + assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} + end + + def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox + @request.session[:user_id] = 2 + issue = Issue.find(3) + issue.attachments.delete_all + get :new, :project_id => 1, :copy_from => 3 + + assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} + end + def test_new_as_copy_with_invalid_issue_should_respond_with_404 @request.session[:user_id] = 2 get :new, :project_id => 1, :copy_from => 99999 @@ -1664,7 +1682,8 @@ class IssuesControllerTest < ActionController::TestCase assert_difference 'Attachment.count', count do assert_no_difference 'Journal.count' do post :create, :project_id => 1, :copy_from => 3, - :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'} + :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, + :copy_attachments => '1' end end end @@ -1673,6 +1692,24 @@ class IssuesControllerTest < ActionController::TestCase assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort end + def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments + @request.session[:user_id] = 2 + issue = Issue.find(3) + count = issue.attachments.count + assert count > 0 + + assert_difference 'Issue.count' do + assert_no_difference 'Attachment.count' do + assert_no_difference 'Journal.count' do + post :create, :project_id => 1, :copy_from => 3, + :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'} + end + end + end + copy = Issue.first(:order => 'id DESC') + assert_equal 0, copy.attachments.count + end + def test_create_as_copy_with_attachments_should_add_new_files @request.session[:user_id] = 2 issue = Issue.find(3) @@ -1684,6 +1721,7 @@ class IssuesControllerTest < ActionController::TestCase assert_no_difference 'Journal.count' 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 end