summaryrefslogtreecommitdiffstats
path: root/app/models/issue.rb
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2021-11-08 14:22:06 +0000
committerGo MAEDA <maeda@farend.jp>2021-11-08 14:22:06 +0000
commit578e367c8c95aaf0ae14ecee038a28c5294c16ac (patch)
tree117008563ac20f34a0a4eaa74d6c8991ea6668e3 /app/models/issue.rb
parent68fce8e97d1634f9c975dd4fabbd746a8dcd02c0 (diff)
downloadredmine-578e367c8c95aaf0ae14ecee038a28c5294c16ac.tar.gz
redmine-578e367c8c95aaf0ae14ecee038a28c5294c16ac.zip
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
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r--app/models/issue.rb30
1 files changed, 28 insertions, 2 deletions
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)