Browse Source

Configurable behavour for linking issues on copy (#18500).

git-svn-id: http://svn.redmine.org/redmine/trunk@13668 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/3.0.0
Jean-Philippe Lang 9 years ago
parent
commit
30d65829b8

+ 15
- 2
app/controllers/issues_controller.rb View File

@@ -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

+ 10
- 0
app/helpers/settings_helper.rb View File

@@ -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, ''],

+ 8
- 0
app/views/issues/bulk_edit.html.erb View File

@@ -97,6 +97,14 @@
</p>
<% 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 %>
<%= hidden_field_tag 'copy_attachments', '0' %>
<p>

+ 6
- 0
app/views/issues/new.html.erb View File

@@ -11,6 +11,12 @@
<%= render :partial => 'issues/form', :locals => {:f => f} %>
</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? %>
<p>
<label for="copy_attachments"><%= l(:label_copy_attachments) %></label>

+ 2
- 0
app/views/settings/_issues.html.erb View File

@@ -3,6 +3,8 @@
<div class="box tabular settings">
<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_check_box :issue_group_assignment %></p>

+ 3
- 0
config/locales/en.yml View File

@@ -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

+ 3
- 0
config/locales/fr.yml View File

@@ -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

+ 2
- 0
config/settings.yml View File

@@ -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:

+ 46
- 35
test/functional/issues_controller_test.rb View File

@@ -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'
}

Loading…
Cancel
Save