git-svn-id: http://svn.redmine.org/redmine/trunk@13668 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/3.0.0
if @copy | if @copy | ||||
issue = orig_issue.copy({}, | issue = orig_issue.copy({}, | ||||
:attachments => params[:copy_attachments].present?, | :attachments => params[:copy_attachments].present?, | ||||
:subtasks => params[:copy_subtasks].present? | |||||
:subtasks => params[:copy_subtasks].present?, | |||||
:link => link_copy?(params[:link_copy]) | |||||
) | ) | ||||
else | else | ||||
issue = orig_issue | issue = orig_issue | ||||
if params[:copy_from] | if params[:copy_from] | ||||
begin | begin | ||||
@copy_from = Issue.visible.find(params[:copy_from]) | @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_attachments = params[:copy_attachments].present? || request.get? | ||||
@copy_subtasks = params[:copy_subtasks].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 | rescue ActiveRecord::RecordNotFound | ||||
render_404 | render_404 | ||||
return | return | ||||
end | end | ||||
end | 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 | end |
content_tag(:label, tag + text, options) | content_tag(:label, tag + text, options) | ||||
end | 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 | def cross_project_subtasks_options | ||||
options = [ | options = [ | ||||
[:label_disabled, ''], | [:label_disabled, ''], |
</p> | </p> | ||||
<% end %> | <% end %> | ||||
<% if @copy && Setting.link_copied_issue == 'ask' %> | |||||
<p> | |||||
<label for='link_copy'><%= l(:label_link_copied_issue) %></label> | |||||
<%= hidden_field_tag 'link_copy', '0' %> | |||||
<%= check_box_tag 'link_copy', '1', params[:link_copy] != 0 %> | |||||
</p> | |||||
<% end %> | |||||
<% if @copy && @attachments_present %> | <% if @copy && @attachments_present %> | ||||
<%= hidden_field_tag 'copy_attachments', '0' %> | <%= hidden_field_tag 'copy_attachments', '0' %> | ||||
<p> | <p> |
<%= render :partial => 'issues/form', :locals => {:f => f} %> | <%= render :partial => 'issues/form', :locals => {:f => f} %> | ||||
</div> | </div> | ||||
<% if @copy_from && Setting.link_copied_issue == 'ask' %> | |||||
<p> | |||||
<label for="link_copy"><%= l(:label_link_copied_issue) %></label> | |||||
<%= check_box_tag 'link_copy', '1', @link_copy %> | |||||
</p> | |||||
<% end %> | |||||
<% if @copy_from && @copy_from.attachments.any? %> | <% if @copy_from && @copy_from.attachments.any? %> | ||||
<p> | <p> | ||||
<label for="copy_attachments"><%= l(:label_copy_attachments) %></label> | <label for="copy_attachments"><%= l(:label_copy_attachments) %></label> |
<div class="box tabular settings"> | <div class="box tabular settings"> | ||||
<p><%= setting_check_box :cross_project_issue_relations %></p> | <p><%= setting_check_box :cross_project_issue_relations %></p> | ||||
<p><%= setting_select :link_copied_issue, link_copied_issue_options %></p> | |||||
<p><%= setting_select :cross_project_subtasks, cross_project_subtasks_options %></p> | <p><%= setting_select :cross_project_subtasks, cross_project_subtasks_options %></p> | ||||
<p><%= setting_check_box :issue_group_assignment %></p> | <p><%= setting_check_box :issue_group_assignment %></p> |
setting_mail_handler_excluded_filenames: Exclude attachments by name | 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_anonymous: Force default language for anonymous users | ||||
setting_force_default_language_for_loggedin: Force default language for logged-in 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_project: Create project | ||||
permission_add_subprojects: Create subprojects | permission_add_subprojects: Create subprojects | ||||
label_users_visibility_all: All active users | label_users_visibility_all: All active users | ||||
label_users_visibility_members_of_visible_projects: Members of visible projects | label_users_visibility_members_of_visible_projects: Members of visible projects | ||||
label_edit_attachments: Edit attached files | label_edit_attachments: Edit attached files | ||||
label_link_copied_issue: Link copied issue | |||||
label_ask: Ask | |||||
button_login: Login | button_login: Login | ||||
button_submit: Submit | button_submit: Submit |
setting_mail_handler_excluded_filenames: Exclure les fichiers attachés par leur nom | 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_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_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_project: Créer un projet | ||||
permission_add_subprojects: Créer des sous-projets | permission_add_subprojects: Créer des sous-projets | ||||
label_users_visibility_all: Tous les utilisateurs actifs | label_users_visibility_all: Tous les utilisateurs actifs | ||||
label_users_visibility_members_of_visible_projects: Membres des projets visibles | label_users_visibility_members_of_visible_projects: Membres des projets visibles | ||||
label_edit_attachments: Modifier les fichiers attachés | label_edit_attachments: Modifier les fichiers attachés | ||||
label_link_copied_issue: Lier la demande copiée | |||||
label_ask: Demander | |||||
button_login: Connexion | button_login: Connexion | ||||
button_submit: Soumettre | button_submit: Soumettre |
# Enables subtasks to be in other projects | # Enables subtasks to be in other projects | ||||
cross_project_subtasks: | cross_project_subtasks: | ||||
default: 'tree' | default: 'tree' | ||||
link_copied_issue: | |||||
default: 'ask' | |||||
issue_group_assignment: | issue_group_assignment: | ||||
default: 0 | default: 0 | ||||
default_issue_start_date_to_creation_date: | default_issue_start_date_to_creation_date: |
assert count > 0 | assert count > 0 | ||||
assert_difference 'Issue.count' do | assert_difference 'Issue.count' do | ||||
assert_difference 'Attachment.count', 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 | ||||
end | end | ||||
copy = Issue.order('id DESC').first | copy = Issue.order('id DESC').first | ||||
assert count > 0 | assert count > 0 | ||||
assert_difference 'Issue.count' do | assert_difference 'Issue.count' do | ||||
assert_no_difference 'Attachment.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 | ||||
end | end | ||||
copy = Issue.order('id DESC').first | copy = Issue.order('id DESC').first | ||||
assert_equal 0, copy.attachments.count | assert_equal 0, copy.attachments.count | ||||
end | 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 | @request.session[:user_id] = 2 | ||||
issue = Issue.find(3) | issue = Issue.find(3) | ||||
count = issue.attachments.count | count = issue.attachments.count | ||||
assert count > 0 | assert count > 0 | ||||
assert_difference 'Issue.count' do | assert_difference 'Issue.count' do | ||||
assert_difference 'Attachment.count', count + 1 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 | ||||
end | end | ||||
copy = Issue.order('id DESC').first | copy = Issue.order('id DESC').first | ||||
@request.session[:user_id] = 2 | @request.session[:user_id] = 2 | ||||
assert_difference 'Issue.count' do | assert_difference 'Issue.count' do | ||||
assert_difference 'IssueRelation.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', | :issue => {:project_id => '1', :tracker_id => '3', | ||||
:status_id => '1', :subject => 'Copy'} | :status_id => '1', :subject => 'Copy'} | ||||
end | end | ||||
assert_equal 1, copy.relations.size | assert_equal 1, copy.relations.size | ||||
end | 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 | def test_create_as_copy_should_copy_subtasks | ||||
@request.session[:user_id] = 2 | @request.session[:user_id] = 2 | ||||
issue = Issue.generate_with_descendants! | issue = Issue.generate_with_descendants! | ||||
count = issue.descendants.count | count = issue.descendants.count | ||||
assert_difference 'Issue.count', count + 1 do | 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 | end | ||||
copy = Issue.where(:parent_id => nil).order('id DESC').first | copy = Issue.where(:parent_id => nil).order('id DESC').first | ||||
assert_equal count, copy.descendants.count | assert_equal count, copy.descendants.count | ||||
@request.session[:user_id] = 2 | @request.session[:user_id] = 2 | ||||
issue = Issue.generate_with_descendants! | issue = Issue.generate_with_descendants! | ||||
assert_difference 'Issue.count', 1 do | 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 | end | ||||
copy = Issue.where(:parent_id => nil).order('id DESC').first | copy = Issue.where(:parent_id => nil).order('id DESC').first | ||||
assert_equal 0, copy.descendants.count | assert_equal 0, copy.descendants.count | ||||
issue = Issue.order('id DESC').first | issue = Issue.order('id DESC').first | ||||
assert_equal 1, issue.journals.size | assert_equal 1, issue.journals.size | ||||
journal = issue.journals.first | journal = issue.journals.first | ||||
assert_equal 1, journal.details.size | |||||
assert_equal 'Copying one issue', journal.notes | assert_equal 'Copying one issue', journal.notes | ||||
end | end | ||||
assert_difference 'Issue.count', 2 do | assert_difference 'Issue.count', 2 do | ||||
assert_difference 'IssueRelation.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 => { | :issue => { | ||||
:project_id => '1' | :project_id => '1' | ||||
} | } |