From 578e367c8c95aaf0ae14ecee038a28c5294c16ac Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Mon, 8 Nov 2021 14:22:06 +0000 Subject: Allow addition/removal of subtasks to show in parent's history (#6033). Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@21273 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/issue.rb b/app/models/issue.rb index 55962f0fe..5c1911eb8 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -117,8 +117,8 @@ class Issue < ActiveRecord::Base after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :delete_selected_attachments, :create_journal # Should be after_create but would be called before previous after_save callbacks - after_save :after_create_from_copy - after_destroy :update_parent_attributes + after_save :after_create_from_copy, :create_parent_issue_journal + after_destroy :update_parent_attributes, :create_parent_issue_journal after_create_commit :send_notification # Returns a SQL conditions string used to find all issues visible by the specified user @@ -1987,6 +1987,32 @@ class Issue < ActiveRecord::Base end end + def create_parent_issue_journal + return if persisted? && !saved_change_to_parent_id? + return if destroyed? && @without_nested_set_update + + child_id = self.id + old_parent_id, new_parent_id = + if persisted? + [parent_id_before_last_save, parent_id] + elsif destroyed? + [parent_id, nil] + else + [nil, parent_id] + end + + if old_parent_id.present? && old_parent_issue = Issue.visible.find_by_id(old_parent_id) + old_parent_issue.init_journal(User.current) + old_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', child_id, nil) + old_parent_issue.save + end + if new_parent_id.present? && new_parent_issue = Issue.visible.find_by_id(new_parent_id) + new_parent_issue.init_journal(User.current) + new_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', nil, child_id) + new_parent_issue.save + end + end + def send_notification if notify? && Setting.notified_events.include?('issue_added') Mailer.deliver_issue_add(self) -- cgit v1.2.3