mirror of
https://github.com/redmine/redmine.git
synced 2025-11-04 20:35:57 +01:00
Handle time entries on subtasks and prevent from reassigning an issue that is going to be deleted (#24718, #24693).
git-svn-id: http://svn.redmine.org/redmine/trunk@16118 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -343,21 +343,28 @@ class IssuesController < ApplicationController
|
||||
|
||||
def destroy
|
||||
raise Unauthorized unless @issues.all?(&:deletable?)
|
||||
@hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
|
||||
|
||||
# all issues and their descendants are about to be deleted
|
||||
issues_and_descendants_ids = Issue.self_and_descendants(@issues).pluck(:id)
|
||||
time_entries = TimeEntry.where(:issue_id => issues_and_descendants_ids)
|
||||
@hours = time_entries.sum(:hours).to_f
|
||||
|
||||
if @hours > 0
|
||||
case params[:todo]
|
||||
when 'destroy'
|
||||
# nothing to do
|
||||
when 'nullify'
|
||||
TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
|
||||
time_entries.update_all(:issue_id => nil)
|
||||
when 'reassign'
|
||||
reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
|
||||
if reassign_to.nil?
|
||||
flash.now[:error] = l(:error_issue_not_found_in_project)
|
||||
return
|
||||
elsif issues_and_descendants_ids.include?(reassign_to.id)
|
||||
flash.now[:error] = l(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted)
|
||||
return
|
||||
else
|
||||
TimeEntry.where(['issue_id IN (?)', @issues]).
|
||||
update_all("issue_id = #{reassign_to.id}")
|
||||
time_entries.update_all(:issue_id => reassign_to.id)
|
||||
end
|
||||
else
|
||||
# display the destroy form if it's a user request
|
||||
|
||||
Reference in New Issue
Block a user