##// END OF EJS Templates
Fixed: Update of time entry fails when the issue has been moved to an other project....
Jean-Philippe Lang -
r896:e2c606e97459
parent child
Show More
@@ -299,29 +299,22 class ProjectsController < ApplicationController
299 # admin is allowed to move issues to any active (visible) project
299 # admin is allowed to move issues to any active (visible) project
300 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
300 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
301 else
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 end
303 end
304 # issue can be moved to any tracker
304 # issue can be moved to any tracker
305 @trackers = Tracker.find(:all)
305 @trackers = Tracker.find(:all)
306 if request.post? && params[:new_project_id] && @projects.collect(&:id).include?(params[:new_project_id].to_i) && params[:new_tracker_id]
306 if request.post? && params[:new_project_id] && @projects.collect(&:id).include?(params[:new_project_id].to_i) && params[:new_tracker_id]
307 new_project = Project.find_by_id(params[:new_project_id])
307 new_project = Project.find_by_id(params[:new_project_id])
308 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
308 new_tracker = params[:new_tracker_id].blank? ? nil : Tracker.find_by_id(params[:new_tracker_id])
309 @issues.each do |i|
309 unsaved_issue_ids = []
310 if new_project && i.project_id != new_project.id
310 @issues.each do |issue|
311 # issue is moved to another project
311 unsaved_issue_ids << issue.id unless issue.move_to(new_project, new_tracker)
312 i.category = nil
312 end
313 i.fixed_version = nil
313 if unsaved_issue_ids.empty?
314 # delete issue relations
314 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
315 i.relations_from.clear
315 else
316 i.relations_to.clear
316 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
317 i.project = new_project
318 end
319 if new_tracker
320 i.tracker = new_tracker
321 end
322 i.save
323 end
317 end
324 flash[:notice] = l(:notice_successful_update)
325 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
318 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
326 end
319 end
327 end
320 end
@@ -61,6 +61,32 class Issue < ActiveRecord::Base
61 self
61 self
62 end
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 def priority_id=(pid)
90 def priority_id=(pid)
65 self.priority = nil
91 self.priority = nil
66 write_attribute(:priority_id, pid)
92 write_attribute(:priority_id, pid)
@@ -10,7 +10,7
10 { :url => { :set_filter => 1 },
10 { :url => { :set_filter => 1 },
11 :update => "content",
11 :update => "content",
12 :with => "Form.serialize('query_form')"
12 :with => "Form.serialize('query_form')"
13 }, :class => 'icon icon-edit' %>
13 }, :class => 'icon icon-checked' %>
14
14
15 <%= link_to_remote l(:button_clear),
15 <%= link_to_remote l(:button_clear),
16 { :url => { :set_filter => 1 },
16 { :url => { :set_filter => 1 },
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -18,7 +18,7
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class IssueTest < Test::Unit::TestCase
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 def test_category_based_assignment
23 def test_category_based_assignment
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)
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,4 +59,15 class IssueTest < Test::Unit::TestCase
59 assert issue2.reload.closed?
59 assert issue2.reload.closed?
60 assert issue3.reload.closed?
60 assert issue3.reload.closed?
61 end
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 end
73 end
General Comments 0
You need to be logged in to leave comments. Login now