Feature #39774 ยป add_logging_for_issue_deletion.patch
| app/models/issue.rb | ||
|---|---|---|
| 120 | 120 |
:update_parent_attributes, :delete_selected_attachments, :create_journal |
| 121 | 121 |
# Should be after_create but would be called before previous after_save callbacks |
| 122 | 122 |
after_save :after_create_from_copy |
| 123 |
after_destroy :update_parent_attributes |
|
| 123 |
after_destroy :update_parent_attributes, :log_issue_deletion
|
|
| 124 | 124 |
# add_auto_watcher needs to run before sending notifications, thus it needs |
| 125 | 125 |
# to be added after send_notification (after_ callbacks are run in inverse order) |
| 126 | 126 |
# https://api.rubyonrails.org/v5.2.3/classes/ActiveSupport/Callbacks/ClassMethods.html#method-i-set_callback |
| ... | ... | |
| 2095 | 2095 |
roles = user.admin ? Role.all.to_a : user.roles_for_project(project) |
| 2096 | 2096 |
roles.select(&:consider_workflow?) |
| 2097 | 2097 |
end |
| 2098 | ||
| 2099 |
def log_issue_deletion |
|
| 2100 |
user = User.current |
|
| 2101 |
Rails.logger.info "Deleted issue: '#{self}' by #{user}"
|
|
| 2102 |
end |
|
| 2098 | 2103 |
end |
| test/unit/issue_test.rb | ||
|---|---|---|
| 2149 | 2149 |
end |
| 2150 | 2150 | |
| 2151 | 2151 |
def test_issue_destroy |
| 2152 |
Issue.find(1).destroy |
|
| 2152 |
issue = Issue.find(1) |
|
| 2153 |
Rails.logger.expects(:info).with("Deleted issue: '#{issue}' by #{User.current}")
|
|
| 2154 |
issue.destroy |
|
| 2153 | 2155 |
assert_nil Issue.find_by_id(1) |
| 2154 | 2156 |
assert_nil TimeEntry.find_by_issue_id(1) |
| 2155 | 2157 |
end |