Loading Changelog.md +1 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ after you've upgraded. * Cleanup relayables where the signature is missing [#7637](https://github.com/diaspora/diaspora/pull/7637) * Avoid page to jump to top after a post deletion [#7638](https://github.com/diaspora/diaspora/pull/7638) * Handle duplicate account deletions [#7639](https://github.com/diaspora/diaspora/pull/7639) * Handle duplicate account migrations [#7641](https://github.com/diaspora/diaspora/pull/7641) ## Features * Ask for confirmation when leaving a submittable comment field [#7530](https://github.com/diaspora/diaspora/pull/7530) Loading lib/diaspora/federation/receive.rb +7 −4 Original line number Diff line number Diff line Loading @@ -18,11 +18,14 @@ module Diaspora end def self.account_migration(entity) old_person = author_of(entity) profile = profile(entity.profile) AccountMigration.create!( old_person: Person.by_account_identifier(entity.author), new_person: profile.person ) return if AccountMigration.where(old_person: old_person, new_person: profile.person).exists? AccountMigration.create!(old_person: old_person, new_person: profile.person) rescue => e # rubocop:disable Lint/RescueWithoutErrorClass raise e unless AccountMigration.where(old_person: old_person, new_person: profile.person).exists? logger.warn "ignoring error on receive #{entity}: #{e.class}: #{e.message}" nil end def self.comment(entity) Loading spec/integration/federation/receive_federation_messages_spec.rb +5 −4 Original line number Diff line number Diff line Loading @@ -58,11 +58,12 @@ describe "Receive federation messages feature" do expect(AccountMigration.find_by(old_person: sender.person, new_person: new_user.person)).to be_performed end it "doesn't accept the same migration for the second time" do it "doesn't run the same migration for the second time" do run_migration expect { expect_any_instance_of(AccountMigration).not_to receive(:perform!) run_migration }.to raise_error(ActiveRecord::RecordInvalid) expect(AccountMigration.where(old_person: sender.person, new_person: new_user.person).count).to eq(1) expect(AccountMigration.find_by(old_person: sender.person, new_person: new_user.person)).to be_performed end it "doesn't accept second migration for the same sender" do Loading spec/lib/diaspora/federation/receive_spec.rb +21 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,27 @@ describe Diaspora::Federation::Receive do expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy end it "ignores duplicate the account migrations" do AccountMigration.create(old_person: sender, new_person: new_person) expect(AccountMigration).not_to receive(:create!) expect(Diaspora::Federation::Receive.account_migration(account_migration_entity)).to be_nil expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy end it "handles race conditions on parallel receive" do expect(AccountMigration).to receive(:create!) do AccountMigration.create(old_person: sender, new_person: new_person) raise "Some database error" end expect(Diaspora::Federation::Receive.account_migration(account_migration_entity)).to be_nil expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy end end describe ".comment" do Loading Loading
Changelog.md +1 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ after you've upgraded. * Cleanup relayables where the signature is missing [#7637](https://github.com/diaspora/diaspora/pull/7637) * Avoid page to jump to top after a post deletion [#7638](https://github.com/diaspora/diaspora/pull/7638) * Handle duplicate account deletions [#7639](https://github.com/diaspora/diaspora/pull/7639) * Handle duplicate account migrations [#7641](https://github.com/diaspora/diaspora/pull/7641) ## Features * Ask for confirmation when leaving a submittable comment field [#7530](https://github.com/diaspora/diaspora/pull/7530) Loading
lib/diaspora/federation/receive.rb +7 −4 Original line number Diff line number Diff line Loading @@ -18,11 +18,14 @@ module Diaspora end def self.account_migration(entity) old_person = author_of(entity) profile = profile(entity.profile) AccountMigration.create!( old_person: Person.by_account_identifier(entity.author), new_person: profile.person ) return if AccountMigration.where(old_person: old_person, new_person: profile.person).exists? AccountMigration.create!(old_person: old_person, new_person: profile.person) rescue => e # rubocop:disable Lint/RescueWithoutErrorClass raise e unless AccountMigration.where(old_person: old_person, new_person: profile.person).exists? logger.warn "ignoring error on receive #{entity}: #{e.class}: #{e.message}" nil end def self.comment(entity) Loading
spec/integration/federation/receive_federation_messages_spec.rb +5 −4 Original line number Diff line number Diff line Loading @@ -58,11 +58,12 @@ describe "Receive federation messages feature" do expect(AccountMigration.find_by(old_person: sender.person, new_person: new_user.person)).to be_performed end it "doesn't accept the same migration for the second time" do it "doesn't run the same migration for the second time" do run_migration expect { expect_any_instance_of(AccountMigration).not_to receive(:perform!) run_migration }.to raise_error(ActiveRecord::RecordInvalid) expect(AccountMigration.where(old_person: sender.person, new_person: new_user.person).count).to eq(1) expect(AccountMigration.find_by(old_person: sender.person, new_person: new_user.person)).to be_performed end it "doesn't accept second migration for the same sender" do Loading
spec/lib/diaspora/federation/receive_spec.rb +21 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,27 @@ describe Diaspora::Federation::Receive do expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy end it "ignores duplicate the account migrations" do AccountMigration.create(old_person: sender, new_person: new_person) expect(AccountMigration).not_to receive(:create!) expect(Diaspora::Federation::Receive.account_migration(account_migration_entity)).to be_nil expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy end it "handles race conditions on parallel receive" do expect(AccountMigration).to receive(:create!) do AccountMigration.create(old_person: sender, new_person: new_person) raise "Some database error" end expect(Diaspora::Federation::Receive.account_migration(account_migration_entity)).to be_nil expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy end end describe ".comment" do Loading