Revision 909
Added by Jean-Philippe Lang over 17 years ago
trunk/app/controllers/projects_controller.rb | ||
---|---|---|
299 | 299 |
# admin is allowed to move issues to any active (visible) project |
300 | 300 |
@projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name') |
301 | 301 |
else |
302 |
User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
|
|
302 |
User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
|
|
303 | 303 |
end |
304 | 304 |
# issue can be moved to any tracker |
305 | 305 |
@trackers = Tracker.find(:all) |
306 | 306 |
if request.post? && params[:new_project_id] && @projects.collect(&:id).include?(params[:new_project_id].to_i) && params[:new_tracker_id] |
307 | 307 |
new_project = Project.find_by_id(params[:new_project_id]) |
308 |
new_tracker = Tracker.find_by_id(params[:new_tracker_id]) |
|
309 |
@issues.each do |i| |
|
310 |
if new_project && i.project_id != new_project.id |
|
311 |
# issue is moved to another project |
|
312 |
i.category = nil |
|
313 |
i.fixed_version = nil |
|
314 |
# delete issue relations |
|
315 |
i.relations_from.clear |
|
316 |
i.relations_to.clear |
|
317 |
i.project = new_project |
|
318 |
end |
|
319 |
if new_tracker |
|
320 |
i.tracker = new_tracker |
|
321 |
end |
|
322 |
i.save |
|
308 |
new_tracker = params[:new_tracker_id].blank? ? nil : Tracker.find_by_id(params[:new_tracker_id]) |
|
309 |
unsaved_issue_ids = [] |
|
310 |
@issues.each do |issue| |
|
311 |
unsaved_issue_ids << issue.id unless issue.move_to(new_project, new_tracker) |
|
323 | 312 |
end |
324 |
flash[:notice] = l(:notice_successful_update) |
|
313 |
if unsaved_issue_ids.empty? |
|
314 |
flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
315 |
else |
|
316 |
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
317 |
end |
|
325 | 318 |
redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
326 | 319 |
end |
327 | 320 |
end |
trunk/app/models/issue.rb | ||
---|---|---|
61 | 61 |
self |
62 | 62 |
end |
63 | 63 |
|
64 |
# Move an issue to a new project and tracker |
|
65 |
def move_to(new_project, new_tracker = nil) |
|
66 |
transaction do |
|
67 |
if new_project && project_id != new_project.id |
|
68 |
# delete issue relations |
|
69 |
self.relations_from.clear |
|
70 |
self.relations_to.clear |
|
71 |
# issue is moved to another project |
|
72 |
self.category = nil |
|
73 |
self.fixed_version = nil |
|
74 |
self.project = new_project |
|
75 |
end |
|
76 |
if new_tracker |
|
77 |
self.tracker = new_tracker |
|
78 |
end |
|
79 |
if save |
|
80 |
# Manually update project_id on related time entries |
|
81 |
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) |
|
82 |
else |
|
83 |
rollback_db_transaction |
|
84 |
return false |
|
85 |
end |
|
86 |
end |
|
87 |
return true |
|
88 |
end |
|
89 |
|
|
64 | 90 |
def priority_id=(pid) |
65 | 91 |
self.priority = nil |
66 | 92 |
write_attribute(:priority_id, pid) |
trunk/app/views/issues/index.rhtml | ||
---|---|---|
10 | 10 |
{ :url => { :set_filter => 1 }, |
11 | 11 |
:update => "content", |
12 | 12 |
:with => "Form.serialize('query_form')" |
13 |
}, :class => 'icon icon-edit' %>
|
|
13 |
}, :class => 'icon icon-checked' %>
|
|
14 | 14 |
|
15 | 15 |
<%= link_to_remote l(:button_clear), |
16 | 16 |
{ :url => { :set_filter => 1 }, |
trunk/test/unit/issue_test.rb | ||
---|---|---|
18 | 18 |
require File.dirname(__FILE__) + '/../test_helper' |
19 | 19 |
|
20 | 20 |
class IssueTest < Test::Unit::TestCase |
21 |
fixtures :projects, :users, :members, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values |
|
21 |
fixtures :projects, :users, :members, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :time_entries
|
|
22 | 22 |
|
23 | 23 |
def test_category_based_assignment |
24 | 24 |
issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1) |
... | ... | |
59 | 59 |
assert issue2.reload.closed? |
60 | 60 |
assert issue3.reload.closed? |
61 | 61 |
end |
62 |
|
|
63 |
def test_move_to_another_project |
|
64 |
issue = Issue.find(1) |
|
65 |
assert issue.move_to(Project.find(2)) |
|
66 |
issue.reload |
|
67 |
assert_equal 2, issue.project_id |
|
68 |
# Category removed |
|
69 |
assert_nil issue.category |
|
70 |
# Make sure time entries were move to the target project |
|
71 |
assert_equal 2, issue.time_entries.first.project_id |
|
72 |
end |
|
62 | 73 |
end |
Also available in: Unified diff
Fixed: Update of time entry fails when the issue has been moved to an other project.
Fixed: Error when moving an issue without changing its tracker (Postgresql).