]> source.dussan.org Git - redmine.git/commitdiff
Adds an option of the copy form to enable/disable attachments copy (#3055).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 20 Jan 2012 18:22:43 +0000 (18:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 20 Jan 2012 18:22:43 +0000 (18:22 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8677 e93f8b46-1217-0410-a6f0-8f06a7374b81

49 files changed:
app/controllers/issues_controller.rb
app/models/issue.rb
app/views/issues/new.html.erb
config/locales/ar.yml
config/locales/bg.yml
config/locales/bs.yml
config/locales/ca.yml
config/locales/cs.yml
config/locales/da.yml
config/locales/de.yml
config/locales/el.yml
config/locales/en-GB.yml
config/locales/en.yml
config/locales/es.yml
config/locales/eu.yml
config/locales/fa.yml
config/locales/fi.yml
config/locales/fr.yml
config/locales/gl.yml
config/locales/he.yml
config/locales/hr.yml
config/locales/hu.yml
config/locales/id.yml
config/locales/it.yml
config/locales/ja.yml
config/locales/ko.yml
config/locales/lt.yml
config/locales/lv.yml
config/locales/mk.yml
config/locales/mn.yml
config/locales/nl.yml
config/locales/no.yml
config/locales/pl.yml
config/locales/pt-BR.yml
config/locales/pt.yml
config/locales/ro.yml
config/locales/ru.yml
config/locales/sk.yml
config/locales/sl.yml
config/locales/sr-YU.yml
config/locales/sr.yml
config/locales/sv.yml
config/locales/th.yml
config/locales/tr.yml
config/locales/uk.yml
config/locales/vi.yml
config/locales/zh-TW.yml
config/locales/zh.yml
test/functional/issues_controller_test.rb

index 82fa5f8ea879b4a9b730a1aa96074cfe53f5cf18..e3e6ffedc27427c7ef0716b685c7fa8fa7c8d819 100644 (file)
@@ -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
index 16257bf83f3e477172d4f1ec1ce303e12126a51f..ad91ab4887fefb516a69c12501ba9547325516bc 100644 (file)
@@ -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
index 7ff994de58ddc4dabe4dc63b651b0e3d01d66ac1..bddb62788338b75ae15eaa11c95cffc113349a04 100644 (file)
     <%= render :partial => 'issues/form', :locals => {:f => f} %>
     </div>
 
+    <% if @copy_from && @copy_from.attachments.any? %>
+               <p>
+                       <label for="copy_attachments"><%= l(:label_copy_attachments) %></label>
+                       <%= check_box_tag 'copy_attachments', '1', @copy_attachments %>
+               </p>
+               <% end %>
+
     <p id="attachments_form"><%= label_tag('attachments[1][file]', l(:label_attachment_plural))%><%= render :partial => 'attachments/form' %></p>
 
     <% if @issue.safe_attribute? 'watcher_user_ids' -%>
index cb8bc29eee49e4cddd2b7ba970e4356b3c7b090e..d351550431409d3299b31c32c6e9707ecc0d990f 100644 (file)
@@ -1013,3 +1013,4 @@ ar:
     other: "%{count} قضايا"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index a7acdb2e780e61ada6330de40d71d7e3e49c9830..c3614d254a182131c06ad374ce3bdda2b0c8b95a 100644 (file)
@@ -1011,3 +1011,4 @@ bg:
   description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати
   description_date_from: Въведете начална дата
   description_date_to: Въведете крайна дата
+  label_copy_attachments: Copy attachments
index d75873a686dd6f2a441cd69e238bfb26b669ed69..d593bf7e646e0823159f6190f686b1b7b174576a 100644 (file)
@@ -1027,3 +1027,4 @@ bs:
     other: "%{count} aktivnosti"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 3a8455efef72802f14c35e52f542a955ead2d767..b2f013a54f801eb8d9491dbd2488e99fcebbf96a 100644 (file)
@@ -1015,3 +1015,4 @@ ca:
     other: "%{count} assumptes"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 858a656339eb076e328d741c1a293662341c6761..d358bd4e07d207d0daeaa9507379422091ad4359 100644 (file)
@@ -1016,3 +1016,4 @@ cs:
     other: "%{count} Úkoly"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 9242e203b59de05d2d8990278fc6955acbacca68..fd93af67e89973a92fd30e70ff331eaccf5d3ed6 100644 (file)
@@ -1030,3 +1030,4 @@ da:
     other: "%{count} sager"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 1582454b091a2ed249314319aca3af2d996e094e..ccb5d56a7012d1fd1f3bbf644511e95d2ceb07b0 100644 (file)
@@ -1033,3 +1033,4 @@ de:
     other: "%{count} tickets"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 29a6a938f810c25166363d8ee38ac24cd2cf2539..a5ea7becd26180767994dd938995140f892a3f0e 100644 (file)
@@ -1013,3 +1013,4 @@ el:
     other: "%{count} Θέματα"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index fbf0582824a520c031e6383736bf6b1a178f2fce..0bd2cf138a6cd21f4e87c3bf5410a3b2ab14ece9 100644 (file)
@@ -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
index 6dc4cb3d7445f2e39544237017a0338f7fbcee2b..091238385ed1ceae44a1a17d2471f79040bc13e4 100644 (file)
@@ -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
index d9c53a72e3ef9ccebdbed7ee6a65269e82b23224..d4cf9af9deb597443a221ca43325e80bbcb8b3cc 100644 (file)
@@ -1050,3 +1050,4 @@ es:
     other: "%{count} peticiones"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 3bf89efa2f42696bb857e07a9b9e85e51ac6f1c3..8e24109062bee9861461150bc4558da8ec9b4de4 100644 (file)
@@ -1016,3 +1016,4 @@ eu:
     other: "%{count} zereginak"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index f02f33de9398d5fb7aff6274d4cc1cda330f26d0..b98fe1051daa328f508ba9a69178dccb46f79fef 100644 (file)
@@ -1015,3 +1015,4 @@ fa:
     other: "%{count} پیامد"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 4585fb9d4470f0300657d0bf03cd59d893c3db51..4e3e9599a3989a9be93ca18057130b02a486149e 100644 (file)
@@ -1034,3 +1034,4 @@ fi:
     other: "%{count} tapahtumat"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 904c3a6c54ce622b77206626618f5888c5cc1ab2..846648da7ddcbcf0af55504146f8df49036d3fa1 100644 (file)
@@ -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
index 3f28af4c762b8b28f5059f2ad0f829565a143de4..a1c66556cf67b4e6b618a4c540adb415e2237bce 100644 (file)
@@ -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
index bb604c2f70f103b70a981bfbb2ae8a263988f3b6..aaa5d340eeba60f6d39bc0e8cbb84528e287d4aa 100644 (file)
@@ -1018,3 +1018,4 @@ he:
     other: "%{count} נושאים"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 78b33c10b6d51ab162e7bb8903a404228a2602ff..13e779d3a7bf15061ce293364fd77d0c58e2b0df 100644 (file)
@@ -1019,3 +1019,4 @@ hr:
     other: "%{count} predmeti"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 8c78d8a578d7f0ae3f3925ba623b43d9807baaed..4f947f9918991e92dfdbc5b2c1f4a455dd60ae45 100644 (file)
     other: "%{count} feladatok"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 3ba2bc5f6535c22b843e099e9a0a4476dfaf716c..c355869983e7d4235acd0844c78f98c829637d98 100644 (file)
@@ -1019,3 +1019,4 @@ id:
     other: "%{count} masalah"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index eb6c804f36c36dd48f2cff86b114be4b781692a5..74647fb2c6b50e5a96d7dabf90a48f91d5384f7d 100644 (file)
@@ -1014,3 +1014,4 @@ it:
     other: "%{count} segnalazioni"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 04d71e80f57438cbd530e5ac53ecbb0c9748ec54..0c7ebe1ba185ecb3bf919fcaeb40f84bf6d896e1 100644 (file)
@@ -1043,3 +1043,4 @@ ja:
     other: "%{count} チケット"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index a78d505b92905749ceb488fdad5ae7aa38a3fba4..6f58cb7a1904372a16b06699eef17b81b8a52e82 100644 (file)
@@ -1065,3 +1065,4 @@ ko:
     other: "%{count} 일감"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 4ca8e1eb652227bf90f3abd71b0e2cf9c262dd6c..4e756118aafbc52a8a2ccd1414b34e2a91ac0e64 100644 (file)
@@ -1073,3 +1073,4 @@ lt:
     other: "%{count} darbai"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index aefce5997b204160c8f631cea004cd9d91f44281..bcf2cc46f96c709a7adcbd42c7c50dc1f2bec496 100644 (file)
@@ -1007,3 +1007,4 @@ lv:
     other: "%{count} uzdevumi"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 477dc6b14b081cb6bb05a69bb63e33c1e6940fab..cde40e1443cfadb083d5bdf17845e360c38d1888 100644 (file)
@@ -1013,3 +1013,4 @@ mk:
     other: "%{count} Задачи"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 71cf161dbd0b1a46fe188dc01e95f888c2b57b24..6c4dd0a413b7e4f0c11a39bc23af4fff678ef5de 100644 (file)
@@ -1013,3 +1013,4 @@ mn:
     other: "%{count} Асуудлууд"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index c6fe47b14b3ad2f0641e353f8774d3c4c8b27f1c..bc2582a028cdfa2404c5828474d114a061ab5d48 100644 (file)
@@ -995,3 +995,4 @@ nl:
     other: "%{count} issues"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 7ebb9224e2947d59f5d9c16c63afa4e7d8371bb7..aedbc2acb993963fcf8666dc2ea7491b21a6b185 100644 (file)
     other: "%{count} saker"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index ec348566fdf8808c8db76eb0d82bac0e3245574c..74678aa519328ea153ace17266d0d8789103ae99 100644 (file)
@@ -1030,3 +1030,4 @@ pl:
     other: "%{count} zagadnienia"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index fa266210e1cfe4814645630c8d2a19852f082ab1..3495a5242d535ce22eae5be373abcd1d4ed8970a 100644 (file)
@@ -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
index e07a8041ce07518e5440ad4b3da88297b49b48da..2af5cf733ce37104988e5f410409b05e64e85ace 100644 (file)
@@ -1018,3 +1018,4 @@ pt:
     other: "%{count} tarefas"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 9189226182bfc7f8408d63348492079fc5ec7f3f..69a73910953cdcd552c713efc931da94278dacad 100644 (file)
@@ -1005,3 +1005,4 @@ ro:
     other: "%{count} tichete"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index e386c7b56e4cf46b488762a162171b6abe0441a7..545e50ca6431d7bdc560c561a2674c0b6eb460fc 100644 (file)
@@ -1126,3 +1126,4 @@ ru:
     other: "%{count} Задачи"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 7a939b4335418a7423f54f2e998b9f750313699e..5095d073d46073c5f67ba760f59b074bc04a8921 100644 (file)
@@ -1008,3 +1008,4 @@ sk:
     other: "%{count} Úlohy"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 81f43b1050eb793c586e69bde982a98b779d990b..f2965758091cb79a10af86db9d5a8eebfed2a403 100644 (file)
@@ -1013,3 +1013,4 @@ sl:
     other: "%{count} zahtevki"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 3484785219ea0faf91bea9d98fd29aad58108efc..cfddaeb57c1537733fe229253cee15456f518e58 100644 (file)
@@ -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
index 3a0b1c3ac488f647278ecdd9c1401f6be592388b..5ec55d8a30f1a54619411383d50623c9aff7febd 100644 (file)
@@ -1014,3 +1014,4 @@ sr:
     other: "%{count} Проблеми"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 2408032facb5027161e1139df797b53b21cd437c..5a07696febac6142027966cdfaaabd35e215dbd4 100644 (file)
@@ -1054,3 +1054,4 @@ sv:
     other: "%{count} Ärenden"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 1bcaaa8280c698a6349a357036f5a69513bf67ef..9ceec83b565a22a5c44252d6aa9270d1994d7163 100644 (file)
@@ -1010,3 +1010,4 @@ th:
     other: "%{count} ปัญหา"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 9343f9f46561baf457ec10eefc72cdb24af55541..ad737564605393d434bd1df26946c92d31c41f68 100644 (file)
@@ -1032,3 +1032,4 @@ tr:
     other: "%{count} İşler"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index df9a0ca5623c7e2d4f097cb277c942e88f32aa05..97e6ae36903fe2731633ffd2e895cd456a012dd1 100644 (file)
@@ -1010,3 +1010,4 @@ uk:
     other: "%{count} Питання"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index fb2bf76f8488aae2d69f9d978d287c8b5d98d9dc..2caf05e267458c105c2f9629b4b7e31c6ec243c0 100644 (file)
@@ -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
index f098be1e719a1a42597a7a84e2771a09fc3c8ae6..95b7ba5dbb5d9f459cf0006be5fe569ff30c5102 100644 (file)
     other: "%{count} 問題清單"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 93e3ce4b3f294a8021e7562be42e207f80b65a19..c9503c5616d91f1a109bab70a9c65957e609d797 100644 (file)
@@ -1015,3 +1015,4 @@ zh:
     other: "%{count} 问题"
   label_repository_new: New repository
   field_repository_is_default: Main repository
+  label_copy_attachments: Copy attachments
index 55c4cb932cfcfe36b9394404e22ba7912ee80863..7bc0d711950de959da0243ab63da4b022fa44fed 100644 (file)
@@ -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