diff options
author | Go MAEDA <maeda@farend.jp> | 2024-10-29 01:02:04 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2024-10-29 01:02:04 +0000 |
commit | a253cd163678b3fa6e3d73370f517656b0f7df1b (patch) | |
tree | 8d9a1948d24d82b95e79b8497255557dcb05ec38 | |
parent | 48a7fd50cb491e590479e9a4455c0fc5a3fe69ac (diff) | |
download | redmine-a253cd163678b3fa6e3d73370f517656b0f7df1b.tar.gz redmine-a253cd163678b3fa6e3d73370f517656b0f7df1b.zip |
Fix: `updated_by_id` in Journal points to a deleted user instead of an anonymous user (#41572).
Patch by Go MAEDA (user:maeda).
git-svn-id: https://svn.redmine.org/redmine/trunk@23169 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/user.rb | 1 | ||||
-rw-r--r-- | test/unit/user_test.rb | 7 |
2 files changed, 7 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index cc4489662..4ce63f809 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -945,6 +945,7 @@ class User < Principal Issue.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id]) Issue.where(['assigned_to_id = ?', id]).update_all('assigned_to_id = NULL') Journal.where(['user_id = ?', id]).update_all(['user_id = ?', substitute.id]) + Journal.where(['updated_by_id = ?', id]).update_all(['updated_by_id = ?', substitute.id]) JournalDetail. where(["property = 'attr' AND prop_key = 'assigned_to_id' AND old_value = ?", id.to_s]). update_all(['old_value = ?', substitute.id.to_s]) diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 34c055c2b..2de0b45db 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -308,12 +308,17 @@ class UserTest < ActiveSupport::TestCase def test_destroy_should_update_journals issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') + # Prepare a journal with both user_id and updated_by_id set to 2 issue.init_journal(User.find(2), "update") issue.save! + journal = issue.journals.first + journal.update_columns(updated_by_id: 2) User.find(2).destroy assert_nil User.find_by_id(2) - assert_equal User.anonymous, issue.journals.first.reload.user + journal.reload + assert_equal User.anonymous, journal.user + assert_equal User.anonymous, journal.updated_by end def test_destroy_should_update_journal_details_old_value |