create shard associations for user merge users
these have been created as the user does things on the cross shard objects, but we should they should be created when the user is merged. This also allows us to put FKs on the columns. refs CORE-2572 test plan - specs should pass Change-Id: I9364653b9c16b893291709943020c5989ae798a5 Reviewed-on: https://gerrit.instructure.com/185440 Tested-by: Jenkins Reviewed-by: James Williams <jamesw@instructure.com> QA-Review: James Williams <jamesw@instructure.com> Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
7d913e25d8
commit
886e00b554
|
@ -32,6 +32,9 @@ class UserMerge
|
|||
def into(target_user)
|
||||
return unless target_user
|
||||
return if target_user == from_user
|
||||
target_user.associate_with_shard(from_user.shard, :shadow)
|
||||
# we also store records for the from_user on the target shard for a split
|
||||
from_user.associate_with_shard(target_user.shard, :shadow)
|
||||
user_merge_data = target_user.shard.activate do
|
||||
UserMergeData.create!(user: target_user, from_user: from_user)
|
||||
end
|
||||
|
@ -250,9 +253,11 @@ class UserMerge
|
|||
user_merge_data.add_more_data(target_user.as_observer_observation_links.where(user_id: from_user), user: target_user, data: data)
|
||||
@data = []
|
||||
target_user.as_observer_observation_links.where(user_id: from_user).destroy_all
|
||||
target_user.associate_with_shard(from_user.shard) if from_user.as_observer_observation_links.exists?
|
||||
from_user.as_observer_observation_links.update_all(observer_id: target_user.id)
|
||||
xor_observer_ids = UserObservationLink.where(student: [from_user, target_user]).distinct.pluck(:observer_id)
|
||||
from_user.as_student_observation_links.where(observer_id: target_user.as_student_observation_links.map(&:observer_id)).destroy_all
|
||||
target_user.associate_with_shard(from_user.shard) if from_user.as_observer_observation_links.exists?
|
||||
from_user.as_student_observation_links.update_all(user_id: target_user.id)
|
||||
# for any observers not already watching both users, make sure they have
|
||||
# any missing observer enrollments added
|
||||
|
@ -377,6 +382,8 @@ class UserMerge
|
|||
remove_self_observers(target_user, user_merge_data)
|
||||
# move all the enrollments that have not been marked as deleted to the target user
|
||||
to_move = Enrollment.active.where(column => from_user)
|
||||
# upgrade to strong association if there are any enrollments
|
||||
target_user.associate_with_shard(from_user.shard) if to_move.exists?
|
||||
user_merge_data.build_more_data(to_move, data: data)
|
||||
to_move.update_all(column => target_user.id)
|
||||
end
|
||||
|
|
|
@ -847,7 +847,8 @@ describe UserMerge do
|
|||
UserMerge.from(user1).into(@user2)
|
||||
run_jobs
|
||||
|
||||
expect(@user2.attachments.not_deleted.count).to eq 5
|
||||
# 3 from user1, and 3 from @user2
|
||||
expect(@user2.attachments.not_deleted.count).to eq 6
|
||||
|
||||
new_user2_attachment1 = @user2.attachments.not_deleted.detect{|a| a.md5 == user1_attachment2.md5 && a.id != @user2_attachment2.id}
|
||||
expect(new_user2_attachment1.root_attachment).to eq @user2_attachment2
|
||||
|
|
Loading…
Reference in New Issue