##// END OF EJS Templates
Merged r4292 from trunk....
Eric Davis -
r4216:1ee7954f44d6
parent child
Show More
@@ -1,65 +1,68
1 class IssueMovesController < ApplicationController
1 class IssueMovesController < ApplicationController
2 default_search_scope :issues
2 default_search_scope :issues
3 before_filter :find_issues
3 before_filter :find_issues
4 before_filter :authorize
4 before_filter :authorize
5
5
6 def new
6 def new
7 prepare_for_issue_move
7 prepare_for_issue_move
8 render :layout => false if request.xhr?
8 render :layout => false if request.xhr?
9 end
9 end
10
10
11 def create
11 def create
12 prepare_for_issue_move
12 prepare_for_issue_move
13
13
14 if request.post?
14 if request.post?
15 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
15 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
16 unsaved_issue_ids = []
16 unsaved_issue_ids = []
17 moved_issues = []
17 moved_issues = []
18 @issues.each do |issue|
18 @issues.each do |issue|
19 issue.reload
19 issue.reload
20 issue.init_journal(User.current)
20 issue.init_journal(User.current)
21 issue.current_journal.notes = @notes if @notes.present?
21 call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
22 call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
22 if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
23 if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
23 moved_issues << r
24 moved_issues << r
24 else
25 else
25 unsaved_issue_ids << issue.id
26 unsaved_issue_ids << issue.id
26 end
27 end
27 end
28 end
28 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
29 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
29
30
30 if params[:follow]
31 if params[:follow]
31 if @issues.size == 1 && moved_issues.size == 1
32 if @issues.size == 1 && moved_issues.size == 1
32 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
33 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
33 else
34 else
34 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
35 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
35 end
36 end
36 else
37 else
37 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
38 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
38 end
39 end
39 return
40 return
40 end
41 end
41 end
42 end
42
43
43 private
44 private
44
45
45 def prepare_for_issue_move
46 def prepare_for_issue_move
46 @issues.sort!
47 @issues.sort!
47 @copy = params[:copy_options] && params[:copy_options][:copy]
48 @copy = params[:copy_options] && params[:copy_options][:copy]
48 @allowed_projects = Issue.allowed_target_projects_on_move
49 @allowed_projects = Issue.allowed_target_projects_on_move
49 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
50 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
50 @target_project ||= @project
51 @target_project ||= @project
51 @trackers = @target_project.trackers
52 @trackers = @target_project.trackers
52 @available_statuses = Workflow.available_statuses(@project)
53 @available_statuses = Workflow.available_statuses(@project)
54 @notes = params[:notes]
55 @notes ||= ''
53 end
56 end
54
57
55 def extract_changed_attributes_for_move(params)
58 def extract_changed_attributes_for_move(params)
56 changed_attributes = {}
59 changed_attributes = {}
57 [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
60 [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
58 unless params[valid_attribute].blank?
61 unless params[valid_attribute].blank?
59 changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
62 changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
60 end
63 end
61 end
64 end
62 changed_attributes
65 changed_attributes
63 end
66 end
64
67
65 end
68 end
@@ -1,62 +1,67
1 <h2><%= @copy ? l(:button_copy) : l(:button_move) %></h2>
1 <h2><%= @copy ? l(:button_copy) : l(:button_move) %></h2>
2
2
3 <ul>
3 <ul>
4 <% @issues.each do |issue| -%>
4 <% @issues.each do |issue| -%>
5 <li><%= link_to_issue issue %></li>
5 <li><%= link_to_issue issue %></li>
6 <% end -%>
6 <% end -%>
7 </ul>
7 </ul>
8
8
9 <% form_tag({:action => 'create'}, :id => 'move_form') do %>
9 <% form_tag({:action => 'create'}, :id => 'move_form') do %>
10 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
10 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %>
11
11
12 <div class="box tabular">
12 <div class="box tabular">
13 <p><label for="new_project_id"><%=l(:field_project)%>:</label>
13 <p><label for="new_project_id"><%=l(:field_project)%>:</label>
14 <%= select_tag "new_project_id",
14 <%= select_tag "new_project_id",
15 project_tree_options_for_select(@allowed_projects, :selected => @target_project),
15 project_tree_options_for_select(@allowed_projects, :selected => @target_project),
16 :onchange => remote_function(:url => { :action => 'new' },
16 :onchange => remote_function(:url => { :action => 'new' },
17 :method => :get,
17 :method => :get,
18 :update => 'content',
18 :update => 'content',
19 :with => "Form.serialize('move_form')") %></p>
19 :with => "Form.serialize('move_form')") %></p>
20
20
21 <p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
21 <p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
22 <%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
22 <%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
23
23
24 <p>
24 <p>
25 <label><%= l(:field_assigned_to) %></label>
25 <label><%= l(:field_assigned_to) %></label>
26 <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
26 <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
27 content_tag('option', l(:label_nobody), :value => 'none') +
27 content_tag('option', l(:label_nobody), :value => 'none') +
28 options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
28 options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
29 </p>
29 </p>
30
30
31 <p>
31 <p>
32 <label><%= l(:field_status) %></label>
32 <label><%= l(:field_status) %></label>
33 <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
33 <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
34 </p>
34 </p>
35
35
36 <p>
36 <p>
37 <label><%= l(:field_priority) %></label>
37 <label><%= l(:field_priority) %></label>
38 <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(IssuePriority.all, :id, :name)) %>
38 <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(IssuePriority.all, :id, :name)) %>
39 </p>
39 </p>
40
40
41 <p>
41 <p>
42 <label><%= l(:field_start_date) %></label>
42 <label><%= l(:field_start_date) %></label>
43 <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %>
43 <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %>
44 </p>
44 </p>
45
45
46 <p>
46 <p>
47 <label><%= l(:field_due_date) %></label>
47 <label><%= l(:field_due_date) %></label>
48 <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
48 <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
49 </p>
49 </p>
50
50
51 <fieldset><legend><%= l(:field_notes) %></legend>
52 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
53 <%= wikitoolbar_for 'notes' %>
54 </fieldset>
55
51 <%= call_hook(:view_issues_move_bottom, :issues => @issues, :target_project => @target_project, :copy => !!@copy) %>
56 <%= call_hook(:view_issues_move_bottom, :issues => @issues, :target_project => @target_project, :copy => !!@copy) %>
52 </div>
57 </div>
53
58
54 <% if @copy %>
59 <% if @copy %>
55 <%= hidden_field_tag("copy_options[copy]", "1") %>
60 <%= hidden_field_tag("copy_options[copy]", "1") %>
56 <%= submit_tag l(:button_copy) %>
61 <%= submit_tag l(:button_copy) %>
57 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
62 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
58 <% else %>
63 <% else %>
59 <%= submit_tag l(:button_move) %>
64 <%= submit_tag l(:button_move) %>
60 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
65 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
61 <% end %>
66 <% end %>
62 <% end %>
67 <% end %>
@@ -1,112 +1,124
1 require File.dirname(__FILE__) + '/../test_helper'
1 require File.dirname(__FILE__) + '/../test_helper'
2
2
3 class IssueMovesControllerTest < ActionController::TestCase
3 class IssueMovesControllerTest < ActionController::TestCase
4 fixtures :all
4 fixtures :all
5
5
6 def setup
6 def setup
7 User.current = nil
7 User.current = nil
8 end
8 end
9
9
10 def test_create_one_issue_to_another_project
10 def test_create_one_issue_to_another_project
11 @request.session[:user_id] = 2
11 @request.session[:user_id] = 2
12 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
12 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
13 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
13 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
14 assert_equal 2, Issue.find(1).project_id
14 assert_equal 2, Issue.find(1).project_id
15 end
15 end
16
16
17 def test_create_one_issue_to_another_project_should_follow_when_needed
17 def test_create_one_issue_to_another_project_should_follow_when_needed
18 @request.session[:user_id] = 2
18 @request.session[:user_id] = 2
19 post :create, :id => 1, :new_project_id => 2, :follow => '1'
19 post :create, :id => 1, :new_project_id => 2, :follow => '1'
20 assert_redirected_to '/issues/1'
20 assert_redirected_to '/issues/1'
21 end
21 end
22
22
23 def test_bulk_create_to_another_project
23 def test_bulk_create_to_another_project
24 @request.session[:user_id] = 2
24 @request.session[:user_id] = 2
25 post :create, :ids => [1, 2], :new_project_id => 2
25 post :create, :ids => [1, 2], :new_project_id => 2
26 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
26 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
27 # Issues moved to project 2
27 # Issues moved to project 2
28 assert_equal 2, Issue.find(1).project_id
28 assert_equal 2, Issue.find(1).project_id
29 assert_equal 2, Issue.find(2).project_id
29 assert_equal 2, Issue.find(2).project_id
30 # No tracker change
30 # No tracker change
31 assert_equal 1, Issue.find(1).tracker_id
31 assert_equal 1, Issue.find(1).tracker_id
32 assert_equal 2, Issue.find(2).tracker_id
32 assert_equal 2, Issue.find(2).tracker_id
33 end
33 end
34
34
35 def test_bulk_create_to_another_tracker
35 def test_bulk_create_to_another_tracker
36 @request.session[:user_id] = 2
36 @request.session[:user_id] = 2
37 post :create, :ids => [1, 2], :new_tracker_id => 2
37 post :create, :ids => [1, 2], :new_tracker_id => 2
38 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
38 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
39 assert_equal 2, Issue.find(1).tracker_id
39 assert_equal 2, Issue.find(1).tracker_id
40 assert_equal 2, Issue.find(2).tracker_id
40 assert_equal 2, Issue.find(2).tracker_id
41 end
41 end
42
42
43 context "#create via bulk move" do
43 context "#create via bulk move" do
44 should "allow changing the issue priority" do
44 setup do
45 @request.session[:user_id] = 2
45 @request.session[:user_id] = 2
46 end
47
48 should "allow changing the issue priority" do
46 post :create, :ids => [1, 2], :priority_id => 6
49 post :create, :ids => [1, 2], :priority_id => 6
47
50
48 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
51 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
49 assert_equal 6, Issue.find(1).priority_id
52 assert_equal 6, Issue.find(1).priority_id
50 assert_equal 6, Issue.find(2).priority_id
53 assert_equal 6, Issue.find(2).priority_id
51
54
52 end
55 end
56
57 should "allow adding a note when moving" do
58 post :create, :ids => [1, 2], :notes => 'Moving two issues'
59
60 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
61 assert_equal 'Moving two issues', Issue.find(1).journals.last.notes
62 assert_equal 'Moving two issues', Issue.find(2).journals.last.notes
63
64 end
53
65
54 end
66 end
55
67
56 def test_bulk_copy_to_another_project
68 def test_bulk_copy_to_another_project
57 @request.session[:user_id] = 2
69 @request.session[:user_id] = 2
58 assert_difference 'Issue.count', 2 do
70 assert_difference 'Issue.count', 2 do
59 assert_no_difference 'Project.find(1).issues.count' do
71 assert_no_difference 'Project.find(1).issues.count' do
60 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
72 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
61 end
73 end
62 end
74 end
63 assert_redirected_to 'projects/ecookbook/issues'
75 assert_redirected_to 'projects/ecookbook/issues'
64 end
76 end
65
77
66 context "#create via bulk copy" do
78 context "#create via bulk copy" do
67 should "allow not changing the issue's attributes" do
79 should "allow not changing the issue's attributes" do
68 @request.session[:user_id] = 2
80 @request.session[:user_id] = 2
69 issue_before_move = Issue.find(1)
81 issue_before_move = Issue.find(1)
70 assert_difference 'Issue.count', 1 do
82 assert_difference 'Issue.count', 1 do
71 assert_no_difference 'Project.find(1).issues.count' do
83 assert_no_difference 'Project.find(1).issues.count' do
72 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
84 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
73 end
85 end
74 end
86 end
75 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
87 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
76 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
88 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
77 assert_equal issue_before_move.status_id, issue_after_move.status_id
89 assert_equal issue_before_move.status_id, issue_after_move.status_id
78 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
90 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
79 end
91 end
80
92
81 should "allow changing the issue's attributes" do
93 should "allow changing the issue's attributes" do
82 # Fixes random test failure with Mysql
94 # Fixes random test failure with Mysql
83 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
95 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
84 Issue.delete_all("project_id=2")
96 Issue.delete_all("project_id=2")
85
97
86 @request.session[:user_id] = 2
98 @request.session[:user_id] = 2
87 assert_difference 'Issue.count', 2 do
99 assert_difference 'Issue.count', 2 do
88 assert_no_difference 'Project.find(1).issues.count' do
100 assert_no_difference 'Project.find(1).issues.count' do
89 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
101 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
90 end
102 end
91 end
103 end
92
104
93 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
105 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
94 assert_equal 2, copied_issues.size
106 assert_equal 2, copied_issues.size
95 copied_issues.each do |issue|
107 copied_issues.each do |issue|
96 assert_equal 2, issue.project_id, "Project is incorrect"
108 assert_equal 2, issue.project_id, "Project is incorrect"
97 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
109 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
98 assert_equal 3, issue.status_id, "Status is incorrect"
110 assert_equal 3, issue.status_id, "Status is incorrect"
99 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
111 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
100 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
112 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
101 end
113 end
102 end
114 end
103 end
115 end
104
116
105 def test_copy_to_another_project_should_follow_when_needed
117 def test_copy_to_another_project_should_follow_when_needed
106 @request.session[:user_id] = 2
118 @request.session[:user_id] = 2
107 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
119 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
108 issue = Issue.first(:order => 'id DESC')
120 issue = Issue.first(:order => 'id DESC')
109 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
121 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
110 end
122 end
111
123
112 end
124 end
General Comments 0
You need to be logged in to leave comments. Login now