Adds an option of the copy form to enable/disable attachments copy (#3055).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8677 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-01-20 18:22:43 +00:00
parent 8a3623733f
commit fbf30eec7c
49 changed files with 105 additions and 9 deletions

View 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

View 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

View File

@ -11,6 +11,13 @@
<%= 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' -%>

View File

@ -1013,3 +1013,4 @@ ar:
other: "%{count} قضايا"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View File

@ -1011,3 +1011,4 @@ bg:
description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати
description_date_from: Въведете начална дата
description_date_to: Въведете крайна дата
label_copy_attachments: Copy attachments

View 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

View 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

View 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

View 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

View 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

View File

@ -1013,3 +1013,4 @@ el:
other: "%{count} Θέματα"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View 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

View 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

View 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

View File

@ -1015,3 +1015,4 @@ fa:
other: "%{count} پیامد"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View 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

View 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

View File

@ -1018,3 +1018,4 @@ he:
other: "%{count} נושאים"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View File

@ -1032,3 +1032,4 @@
other: "%{count} feladatok"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View 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

View File

@ -1043,3 +1043,4 @@ ja:
other: "%{count} チケット"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View File

@ -1065,3 +1065,4 @@ ko:
other: "%{count} 일감"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View 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

View File

@ -1013,3 +1013,4 @@ mk:
other: "%{count} Задачи"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View File

@ -1013,3 +1013,4 @@ mn:
other: "%{count} Асуудлууд"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View File

@ -1003,3 +1003,4 @@
other: "%{count} saker"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View 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

View 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

View 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

View File

@ -1126,3 +1126,4 @@ ru:
other: "%{count} Задачи"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View 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

View 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

View File

@ -1014,3 +1014,4 @@ sr:
other: "%{count} Проблеми"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View File

@ -1010,3 +1010,4 @@ th:
other: "%{count} ปัญหา"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View File

@ -1010,3 +1010,4 @@ uk:
other: "%{count} Питання"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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

View File

@ -1093,3 +1093,4 @@
other: "%{count} 問題清單"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View File

@ -1015,3 +1015,4 @@ zh:
other: "%{count} 问题"
label_repository_new: New repository
field_repository_is_default: Main repository
label_copy_attachments: Copy attachments

View 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