Skip to content

Commit

Permalink
Fix account merge not transferring editorship of all merged accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Nov 13, 2023
1 parent 1432149 commit 82c9fba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def merge(*others)
other.activities.update_all(trackable_id: id, trackable_type: self.class.name)
other.subscriptions.update_all(user_id: id)
new_collaborations += other.collaborations
new_editable_ids = other.editable_ids
new_editable_ids |= other.editable_ids
attrs.reverse_merge!(other.attributes)
end
self.editable_ids = self.editable_ids | new_editable_ids
Expand Down
13 changes: 11 additions & 2 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ class UserTest < ActiveSupport::TestCase
provider = content_providers(:goblet)
provider.add_editor(user1)
provider.add_editor(user2)
provider2 = content_providers(:iann)
provider2.add_editor(user2)
provider3 = content_providers(:two)
provider3.add_editor(user3)

# Collaborations
workflow1 = workflows(:one)
Expand All @@ -348,12 +352,13 @@ class UserTest < ActiveSupport::TestCase
workflow1.collaborators << user2
workflow2.collaborators << user3


# Test
assert_no_difference('Event.count') do
assert_no_difference('Material.count') do
assert_no_difference('Subscription.count') do
assert_difference('provider.editors.count', -1) do
assert_no_difference('provider2.editors.count') do
assert_no_difference('provider3.editors.count') do
assert_difference('Collaboration.count', -1) do
assert_difference('User.count', -2) do
assert user1.merge(user2, user3)
Expand All @@ -365,6 +370,8 @@ class UserTest < ActiveSupport::TestCase
end
end
end
end
end

assert_equal 'base_user', user1.username
assert_equal user1_id, user1.id
Expand All @@ -387,7 +394,9 @@ class UserTest < ActiveSupport::TestCase
assert_equal user1, subscription1.reload.user
assert_equal user1, subscription2.reload.user

assert_includes provider.reload.editors, user1
assert_equal [user1], provider.reload.editors
assert_equal [user1], provider2.reload.editors
assert_equal [user1], provider3.reload.editors

assert_equal [user1], workflow1.reload.collaborators.to_a
assert_equal [user1], workflow2.reload.collaborators.to_a
Expand Down

0 comments on commit 82c9fba

Please sign in to comment.