Add remote_photo_path to AccountMigration entity

This can be set to the URL on the new pod when photos were
migrated/imported, so other pods can adjust the `remote_photo_path` of
the photos of the old account.
This commit is contained in:
Benjamin Neff 2021-10-23 17:21:12 +02:00
parent 85e12cea93
commit 0d12770262
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
6 changed files with 54 additions and 3 deletions

View file

@ -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=
</signature>
<old_identity>alice@example.org</old_identity>
<remote_photo_path>https://newpod.example.net/uploads/images/</remote_photo_path>
</account_migration>
~~~
[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

View file

@ -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

View file

@ -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

View file

@ -9,6 +9,8 @@ module DiasporaFederation
rule :profile, :not_nil
rule :old_identity, :diaspora_id
rule :remote_photo_path, URI: [:path]
end
end
end

View file

@ -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
</profile>
<signature>#{data[:signature]}</signature>
<old_identity>#{data[:old_identity]}</old_identity>
<remote_photo_path>#{data[:remote_photo_path]}</remote_photo_path>
</account_migration>
XML
@ -165,6 +167,7 @@ XML
</profile>
<signature>#{data[:signature]}</signature>
<old_identity>#{data[:old_identity]}</old_identity>
<remote_photo_path>#{data[:remote_photo_path]}</remote_photo_path>
</account_migration>
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
<account_migration>
<author>#{data[:author]}</author>
<profile>
<author>#{data[:profile].author}</author>
</profile>
<signature>#{data[:signature]}</signature>
</account_migration>
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

View file

@ -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