Store signatures of AccountMigrations if the old person is local
That way it can be re-used when sending the AccountMigrations to other pods again if a message for the migrated account is received. fixes #7902 closes #8309
This commit is contained in:
parent
3cb1e470a4
commit
5714e83ab2
6 changed files with 49 additions and 9 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
* Send `AccountMigration` if receiving message to a migrated account [#8288](https://github.com/diaspora/diaspora/pull/8288)
|
* Send `AccountMigration` if receiving message to a migrated account [#8288](https://github.com/diaspora/diaspora/pull/8288)
|
||||||
* Add podmin mail address to the footer [#8242](https://github.com/diaspora/diaspora/pull/8242)
|
* Add podmin mail address to the footer [#8242](https://github.com/diaspora/diaspora/pull/8242)
|
||||||
* Add username to password-reset mail [#8037](https://github.com/diaspora/diaspora/pull/8037)
|
* Add username to password-reset mail [#8037](https://github.com/diaspora/diaspora/pull/8037)
|
||||||
|
* Resend account migration and deletion for closed recipients [#8309](https://github.com/diaspora/diaspora/pull/8309)
|
||||||
|
|
||||||
# 0.7.15.0
|
# 0.7.15.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddSignatureToAccountMigration < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :account_migrations, :signature, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -26,8 +26,9 @@ module Diaspora
|
||||||
|
|
||||||
def self.account_migration(account_migration)
|
def self.account_migration(account_migration)
|
||||||
DiasporaFederation::Entities::AccountMigration.new(
|
DiasporaFederation::Entities::AccountMigration.new(
|
||||||
author: account_migration.sender.diaspora_handle,
|
author: account_migration.sender.diaspora_handle,
|
||||||
profile: profile(account_migration.new_person.profile)
|
profile: profile(account_migration.new_person.profile),
|
||||||
|
signature: account_migration.signature
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,15 @@ module Diaspora
|
||||||
def self.account_migration(entity)
|
def self.account_migration(entity)
|
||||||
old_person = author_of(entity)
|
old_person = author_of(entity)
|
||||||
profile = profile(entity.profile)
|
profile = profile(entity.profile)
|
||||||
return if AccountMigration.where(old_person: old_person, new_person: profile.person).exists?
|
return if AccountMigration.exists?(old_person: old_person, new_person: profile.person)
|
||||||
AccountMigration.create!(old_person: old_person, new_person: profile.person)
|
|
||||||
rescue => e # rubocop:disable Lint/RescueWithoutErrorClass
|
AccountMigration.create!(old_person: old_person, new_person: profile.person).tap do |migration|
|
||||||
raise e unless AccountMigration.where(old_person: old_person, new_person: profile.person).exists?
|
migration.signature = entity.signature if old_person.local?
|
||||||
|
migration.save!
|
||||||
|
end
|
||||||
|
rescue StandardError => e
|
||||||
|
raise e unless AccountMigration.exists?(old_person: old_person, new_person: profile.person)
|
||||||
|
|
||||||
logger.warn "ignoring error on receive #{entity}: #{e.class}: #{e.message}"
|
logger.warn "ignoring error on receive #{entity}: #{e.class}: #{e.message}"
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,19 @@ describe Diaspora::Federation::Entities do
|
||||||
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::AccountMigration)
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::AccountMigration)
|
||||||
expect(federation_entity.author).to eq(diaspora_entity.old_person.diaspora_handle)
|
expect(federation_entity.author).to eq(diaspora_entity.old_person.diaspora_handle)
|
||||||
expect(federation_entity.profile.author).to eq(diaspora_entity.new_person.diaspora_handle)
|
expect(federation_entity.profile.author).to eq(diaspora_entity.new_person.diaspora_handle)
|
||||||
|
expect(federation_entity.signature).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "builds an account migration with signature" do
|
||||||
|
diaspora_entity = FactoryGirl.build(:account_migration,
|
||||||
|
old_person: FactoryGirl.create(:user).person,
|
||||||
|
signature: "aa")
|
||||||
|
federation_entity = described_class.build(diaspora_entity)
|
||||||
|
|
||||||
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::AccountMigration)
|
||||||
|
expect(federation_entity.author).to eq(diaspora_entity.old_person.diaspora_handle)
|
||||||
|
expect(federation_entity.profile.author).to eq(diaspora_entity.new_person.diaspora_handle)
|
||||||
|
expect(federation_entity.signature).to eq(diaspora_entity.signature)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "builds a comment" do
|
it "builds a comment" do
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,16 @@ describe Diaspora::Federation::Receive do
|
||||||
let(:new_person) { FactoryGirl.create(:person) }
|
let(:new_person) { FactoryGirl.create(:person) }
|
||||||
let(:profile_entity) { Fabricate(:profile_entity, author: new_person.diaspora_handle) }
|
let(:profile_entity) { Fabricate(:profile_entity, author: new_person.diaspora_handle) }
|
||||||
let(:account_migration_entity) {
|
let(:account_migration_entity) {
|
||||||
Fabricate(:account_migration_entity, author: sender.diaspora_handle, profile: profile_entity)
|
Fabricate(:account_migration_entity, author: sender.diaspora_handle, profile: profile_entity, signature: "aa")
|
||||||
}
|
}
|
||||||
|
|
||||||
it "saves the account deletion" do
|
it "saves the account deletion" do
|
||||||
Diaspora::Federation::Receive.account_migration(account_migration_entity)
|
received = Diaspora::Federation::Receive.account_migration(account_migration_entity)
|
||||||
|
|
||||||
expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy
|
migration = AccountMigration.find_by(old_person: sender, new_person: new_person)
|
||||||
|
|
||||||
|
expect(received).to eq(migration)
|
||||||
|
expect(migration.signature).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ignores duplicate the account migrations" do
|
it "ignores duplicate the account migrations" do
|
||||||
|
|
@ -120,6 +123,16 @@ describe Diaspora::Federation::Receive do
|
||||||
|
|
||||||
expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy
|
expect(AccountMigration.exists?(old_person: sender, new_person: new_person)).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "saves signature from the new person if the old person is local" do
|
||||||
|
sender = FactoryGirl.create(:user).person
|
||||||
|
account_migration_entity =
|
||||||
|
Fabricate(:account_migration_entity, author: sender.diaspora_handle, profile: profile_entity, signature: "aa")
|
||||||
|
|
||||||
|
received = Diaspora::Federation::Receive.perform(account_migration_entity)
|
||||||
|
|
||||||
|
expect(received.signature).to eq("aa")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".comment" do
|
describe ".comment" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue