class DiasporaFederation::Entities::AccountMigration

This entity is sent when a person changes their diaspora* ID (e.g. when a user migration from one to another pod happens).

@see Validators::AccountMigrationValidator

Public Class Methods

from_hash(*args) click to toggle source

Calls super and additionally does signature verification for the instantiated entity.

@see DiasporaFederation::Entity.from_hash

Calls superclass method
# File lib/diaspora_federation/entities/account_migration.rb, line 70
def self.from_hash(*args)
  super.tap(&:verify_signature)
end

Public Instance Methods

new_identity() click to toggle source

Returns diaspora* ID of the new person identity. @return [String] diaspora* ID of the new person identity

# File lib/diaspora_federation/entities/account_migration.rb, line 53
def new_identity
  profile&.author
end
old_identity() click to toggle source

Returns diaspora* ID of the old person identity. @return [String] diaspora* ID of the old person identity

# File lib/diaspora_federation/entities/account_migration.rb, line 45
def old_identity
  return @old_identity if author_is_new_id?

  author
end
verify_signature() click to toggle source

Shortcut for calling super method with sensible arguments

@see DiasporaFederation::Entities::Signable#verify_signature

Calls superclass method
# File lib/diaspora_federation/entities/account_migration.rb, line 63
def verify_signature
  super(signer_id, :signature)
end

Private Instance Methods

author_is_new_id?() click to toggle source
# File lib/diaspora_federation/entities/account_migration.rb, line 76
def author_is_new_id?
  author == new_identity
end
enriched_properties() click to toggle source
Calls superclass method
# File lib/diaspora_federation/entities/account_migration.rb, line 84
def enriched_properties
  super.tap do |hash|
    hash[:signature] = signature || sign_with_respective_key
  end
end
sign_with_respective_key() click to toggle source

Sign with the key of the signer_id identity @raise [PrivateKeyNotFound] if the signer’s private key is not found @return [String] A Base64 encoded signature of signature_data with key

# File lib/diaspora_federation/entities/account_migration.rb, line 93
def sign_with_respective_key
  privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, signer_id)
  raise PrivateKeyNotFound, "signer=#{signer_id} obj=#{self}" if privkey.nil?

  sign_with_key(privkey).tap do
    logger.info "event=sign status=complete signature=signature signer=#{signer_id} obj=#{self}"
  end
end
signer_id() click to toggle source
# File lib/diaspora_federation/entities/account_migration.rb, line 80
def signer_id
  author_is_new_id? ? @old_identity : new_identity
end