Skip to content

Commit

Permalink
Correctly transfer 'last_updated_by' for annotations when merging users
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Oct 28, 2024
1 parent 8ef39d5 commit eb69759
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Check warning on line 434 in app/models/user.rb

View check run for this annotation

Codecov / codecov/patch

app/models/user.rb#L433-L434

Added lines #L433 - L434 were not covered by tests
questions.each { |q| q.update!(user: other) }

evaluation_users.each do |eu|
Expand Down
25 changes: 25 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit eb69759

Please sign in to comment.