Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider a36d22d7 rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

Handle duplicate account migrations

closes #7641
parent 2bd9c663
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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)
......
......@@ -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)
......
......@@ -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 {
run_migration
}.to raise_error(ActiveRecord::RecordInvalid)
expect_any_instance_of(AccountMigration).not_to receive(:perform!)
run_migration
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
......
......@@ -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
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter