From eb6975983a1130c3912189c45b9e2eb760c4f1cd Mon Sep 17 00:00:00 2001 From: "jorg.vr" Date: Mon, 28 Oct 2024 11:51:38 +0100 Subject: [PATCH] Correctly transfer 'last_updated_by' for annotations when merging users --- app/models/user.rb | 3 ++- test/models/user_test.rb | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 2eebbfda38..fc4f762a97 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -430,7 +430,8 @@ def merge_into(other, force: false, force_institution: false) events.each { |e| e.update!(user: other) } exports.each { |e| e.update!(user: other) } notifications.each { |n| n.update!(user: other) } - annotations.each { |a| a.update!(user: other, last_updated_by_id: other.id) } + annotations.each { |a| a.update!(user: other) } + Annotation.where(last_updated_by_id: id).find_each { |a| a.update!(last_updated_by: other) } questions.each { |q| q.update!(user: other) } evaluation_users.each do |eu| diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 6c047ae0b2..98ac4b1fc6 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -846,6 +846,31 @@ def setup assert_equal 2, u2.announcement_views.count end + test 'merge should transfer last_updated_by of non owned annotations' do + u1 = create :user + u2 = create :user + + student = create :user + + c = create :course, series_count: 1, exercises_per_series: 1 + c.administrating_members << u1 + c.enrolled_members << student + + s = create :submission, user: student, course: c + + a1 = create :annotation, user: u1, submission: s + a2 = create :annotation, user: create(:user), submission: s + + a2.update(last_updated_by: u1) + + result = u1.merge_into(u2) + + assert result + assert_not u1.persisted? + assert_equal u2, a1.reload.last_updated_by + assert_equal u2, a2.reload.last_updated_by + end + test 'jump back in should return most recent incomplete activity' do user = create :user