update timestamp on discussions when merging users
fixes CNVS-12782 discussions cache some material in the "materialized view". that material may include references to the use being deleted in a user merge. the source material was already being updated correctly by the merge, but the materialized view was not expiring. updating the updated_at on the appropriate topics will force the necessary materialized views to be refreshed. test-plan: - create two distinct users, A and B - as user A, create a discussion topic - as user B, create a second discussion topic - as user A, reply to user B's discussion topic - merge user A into user B - view the first discussion topic; user B should display as the author - view the second discussion topic; user B should display as the reply's author Change-Id: I48948e171b6645a371e92c8413fa289695d3d1a2 Reviewed-on: https://gerrit.instructure.com/34445 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Joel Hough <joel@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Product-Review: Jacob Fugal <jacob@instructure.com>
This commit is contained in:
parent
b735a56fdb
commit
7a722f690c
|
@ -144,11 +144,23 @@ class UserMerge
|
|||
end
|
||||
end
|
||||
from_user.all_conversations.find_each { |c| c.move_to_user(target_user) } unless Shard.current != target_user.shard
|
||||
|
||||
# all topics changing ownership or with entries changing ownership need to be
|
||||
# flagged as updated so the materialized views update
|
||||
begin
|
||||
entries = DiscussionEntry.where(user_id: from_user)
|
||||
DiscussionTopic.where(id: entries.select(['discussion_topic_id'])).update_all(updated_at: Time.now.utc)
|
||||
entries.update_all(user_id: target_user.id)
|
||||
DiscussionTopic.where(user_id: from_user).update_all(user_id: target_user.id, updated_at: Time.now.utc)
|
||||
rescue => e
|
||||
Rails.logger.error "migrating discussions failed: #{e.to_s}"
|
||||
end
|
||||
|
||||
updates = {}
|
||||
['account_users', 'access_tokens', 'asset_user_accesses',
|
||||
'attachments',
|
||||
'calendar_events', 'collaborations',
|
||||
'context_module_progressions', 'discussion_entries', 'discussion_topics',
|
||||
'context_module_progressions',
|
||||
'group_memberships', 'page_comments',
|
||||
'rubric_assessments',
|
||||
'submission_comment_participants', 'user_services', 'web_conferences',
|
||||
|
|
|
@ -352,6 +352,35 @@ describe UserMerge do
|
|||
new_attachment = user2.attachments.not_deleted.detect{|a| a.md5 == attachment2.md5}
|
||||
new_attachment.display_name.should_not == "test.txt" # attachment2 should be copied and renamed because it has unique file data
|
||||
end
|
||||
|
||||
it "should move discussion topics and entries" do
|
||||
topic = course1.discussion_topics.create!(user: user2)
|
||||
entry = topic.discussion_entries.create!(user: user2)
|
||||
|
||||
UserMerge.from(user2).into(user1)
|
||||
|
||||
topic.reload.user.should == user1
|
||||
entry.reload.user.should == user1
|
||||
end
|
||||
|
||||
it "should freshen moved topics" do
|
||||
topic = course1.discussion_topics.create!(user: user2)
|
||||
now = Time.at(5.minutes.from_now.to_i) # truncate milliseconds
|
||||
Timecop.freeze(now) do
|
||||
UserMerge.from(user2).into(user1)
|
||||
topic.reload.updated_at.should == now
|
||||
end
|
||||
end
|
||||
|
||||
it "should freshen topics with moved entries" do
|
||||
topic = course1.discussion_topics.create!(user: user1)
|
||||
entry = topic.discussion_entries.create!(user: user2)
|
||||
now = Time.at(5.minutes.from_now.to_i) # truncate milliseconds
|
||||
Timecop.freeze(now) do
|
||||
UserMerge.from(user2).into(user1)
|
||||
topic.reload.updated_at.should == now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "should update account associations" do
|
||||
|
|
Loading…
Reference in New Issue