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

Use old person private key if relayable author migrated away

We only store signatures for relayables if the author is external, but
if the author becomes external through a migration, the signature is
missing. Lets just use the old persons private key to still be able to
generate a signature for the export.

closes #8310
parent 1570e3fb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -11,6 +11,7 @@
* Ensure the log folder exists [#8287](https://github.com/diaspora/diaspora/pull/8287)
* Limit name length in header [#8313] (https://github.com/diaspora/diaspora/pull/8313)
* Fix fallback avatar in hovercards [#8316](https://github.com/diaspora/diaspora/pull/8316)
* Use old person private key for export if relayable author migrated away [#8310](https://github.com/diaspora/diaspora/pull/8310)
## Features
* Add tags to tumblr posts [#8244](https://github.com/diaspora/diaspora/pull/8244)
......
......@@ -5,11 +5,26 @@
# are used as for federation messages generation.
class FederationEntitySerializer < ActiveModel::Serializer
include SerializerPostProcessing
include Diaspora::Logging
private
def modify_serializable_object(hash)
hash.merge(entity.to_json)
rescue DiasporaFederation::Entities::Relayable::AuthorPrivateKeyNotFound => e
# The author of this relayable probably migrated from this pod to a different pod,
# and we neither have the signature nor the new private key to generate a valid signature.
# But we can use the private key of the old user to generate the signature it had when this entity was created
old_person = AccountMigration.joins(:old_person)
.where("new_person_id = ? AND people.owner_id IS NOT NULL", object.author_id)
.first.old_person
if old_person
logger.info "Using private key of #{old_person.diaspora_handle} to export: #{e.message}"
object.author = old_person
hash.merge(entity.to_json)
else
logger.warn "Skip entity for export because #{e.class}: #{e.message}"
end
end
def entity
......
......@@ -13,9 +13,14 @@ describe Export::OthersDataSerializer do
serializer.associations
end
context "with user's activity" do
before do
DataGenerator.new(user).activity
it "uses old local user private key if the author was migrated away from the pod" do
post = DataGenerator.new(user).status_message_with_activity
old_comment_author = post.comments.first.author
AccountMigration.create!(old_person: old_comment_author, new_person: FactoryGirl.create(:person)).perform!
serializer.associations[:relayables].select {|r| r[:entity_type] == "comment" }.each do |comment|
expect(comment[:entity_data][:author]).to eq(old_comment_author.diaspora_handle)
end
end
end
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