diff --git a/docs/_entities/account_migration.md b/docs/_entities/account_migration.md index a418c4c..7c61aab 100644 --- a/docs/_entities/account_migration.md +++ b/docs/_entities/account_migration.md @@ -14,9 +14,10 @@ This entity is sent when a person changes their diaspora* ID (e.g. when a user m ## Optional Properties -| Property | Type | Description | -| ----------- | ---------------------------- | ------------------------------------------------------------------------------------ | -| `old_identity` | [diaspora\* ID][diaspora-id] | The diaspora\* ID of the closed account. This field is mandatory if the author of the entity is the new identity. | +| Property | Type | Description | +| ------------------- | ---------------------------- | ------------------------------------------------------------------------------------ | +| `old_identity` | [diaspora\* ID][diaspora-id] | The diaspora\* ID of the closed account. This field is mandatory if the author of the entity is the new identity. | +| `remote_photo_path` | [URL][url] | The URL to the path (without filenames) of the migrated photos on the new pod. | ### Signature @@ -59,9 +60,11 @@ AccountMigration:old-diaspora-id@example.org:new-diaspora-id@example.com 07b1OIY6sTUQwV5pbpgFK0uz6W4cu+oQnlg410Q4uISUOdNOlBdYqhZJm62VFhgvzt4TZXfiJgoupFkRjP0BsaVaZuP2zKMNvO3ngWOeJRf2oRK4Ub5cEA/g7yijkRc+7y8r1iLJ31MFb1czyeCsLxw9Ol8SvAJddogGiLHDhjE= alice@example.org + https://newpod.example.net/uploads/images/ ~~~ [diaspora-id]: {{ site.baseurl }}/federation/types.html#diaspora-id [profile]: {{ site.baseurl }}/entities/profile.html [signature]: {{ site.baseurl }}/federation/types.html#signature +[url]: {{ site.baseurl }}/federation/types.html#url diff --git a/lib/diaspora_federation/entities/account_migration.rb b/lib/diaspora_federation/entities/account_migration.rb index 82deed3..dc959b9 100644 --- a/lib/diaspora_federation/entities/account_migration.rb +++ b/lib/diaspora_federation/entities/account_migration.rb @@ -33,6 +33,11 @@ module DiasporaFederation # @return [String] old identity property :old_identity, :string, default: nil + # @!attribute [r] remote_photo_path + # The url to the path of the photos on the new pod. Can be empty if photos weren't migrated. + # @return [String] remote photo path + property :remote_photo_path, :string, optional: true + # Returns diaspora* ID of the old person identity. # @return [String] diaspora* ID of the old person identity def old_identity diff --git a/lib/diaspora_federation/test/factories.rb b/lib/diaspora_federation/test/factories.rb index 38e8d99..f39aed9 100644 --- a/lib/diaspora_federation/test/factories.rb +++ b/lib/diaspora_federation/test/factories.rb @@ -43,6 +43,7 @@ module DiasporaFederation author { Fabricate.sequence(:diaspora_id) } profile {|attrs| Fabricate(:profile_entity, author: attrs[:author]) } old_identity { Fabricate.sequence(:diaspora_id) } + remote_photo_path "https://diaspora.example.tld/uploads/images/" end Fabricator(:person_entity, class_name: DiasporaFederation::Entities::Person) do diff --git a/lib/diaspora_federation/validators/account_migration_validator.rb b/lib/diaspora_federation/validators/account_migration_validator.rb index 36c38be..aab6efa 100644 --- a/lib/diaspora_federation/validators/account_migration_validator.rb +++ b/lib/diaspora_federation/validators/account_migration_validator.rb @@ -9,6 +9,8 @@ module DiasporaFederation rule :profile, :not_nil rule :old_identity, :diaspora_id + + rule :remote_photo_path, URI: [:path] end end end diff --git a/spec/lib/diaspora_federation/entities/account_migration_spec.rb b/spec/lib/diaspora_federation/entities/account_migration_spec.rb index 37852df..4145aa7 100644 --- a/spec/lib/diaspora_federation/entities/account_migration_spec.rb +++ b/spec/lib/diaspora_federation/entities/account_migration_spec.rb @@ -10,6 +10,7 @@ module DiasporaFederation properties = described_class.new(hash).send(:enriched_properties) hash[:signature] = properties[:signature] hash[:profile] = Entities::Profile.new(hash[:profile].to_h.tap {|profile| profile[:edited_at] = nil }) + hash[:remote_photo_path] = "http://localhost:3000/uploads/images/" } } let(:signature_data) { "AccountMigration:#{old_diaspora_id}:#{new_diaspora_id}" } @@ -126,6 +127,7 @@ module DiasporaFederation #{data[:signature]} #{data[:old_identity]} + #{data[:remote_photo_path]} XML @@ -165,6 +167,7 @@ XML #{data[:signature]} #{data[:old_identity]} + #{data[:remote_photo_path]} XML @@ -217,5 +220,31 @@ XML }.to raise_error Entity::ValidationError end end + + context "optional values" do + let(:hash) { + { + author: old_diaspora_id, + profile: Entities::Profile.new(author: new_diaspora_id) + } + } + + it "uses default values when parsing" do + minimal_xml = <<-XML + + #{data[:author]} + + #{data[:profile].author} + + #{data[:signature]} + +XML + + parsed_xml = Nokogiri::XML(minimal_xml).root + parsed_instance = Entity.entity_class(parsed_xml.name).from_xml(parsed_xml) + expect(parsed_instance.old_identity).to eq(data[:author]) + expect(parsed_instance.remote_photo_path).to be_nil + end + end end end diff --git a/spec/lib/diaspora_federation/validators/account_migration_validator_spec.rb b/spec/lib/diaspora_federation/validators/account_migration_validator_spec.rb index e8c4ea5..5a21efd 100644 --- a/spec/lib/diaspora_federation/validators/account_migration_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/account_migration_validator_spec.rb @@ -21,5 +21,16 @@ module DiasporaFederation let(:property) { :old_identity } end end + + describe "#remote_photo_path" do + let(:property) { :remote_photo_path } + + it_behaves_like "a property with a value validation/restriction" do + let(:wrong_values) { [] } + let(:correct_values) { [nil] } + end + + it_behaves_like "a url path validator" + end end end