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