diff --git a/lib/archive_importer.rb b/lib/archive_importer.rb index 937f12480..67ba34a97 100644 --- a/lib/archive_importer.rb +++ b/lib/archive_importer.rb @@ -28,7 +28,10 @@ class ArchiveImporter data.merge!( username: attr[:username], password: attr[:password], - password_confirmation: attr[:password] + password_confirmation: attr[:password], + person: { + profile_attributes: profile_attributes + } ) self.user = User.build(data) user.save! @@ -38,6 +41,14 @@ class ArchiveImporter attr_reader :archive_hash + def profile_attributes + allowed_keys = %w[first_name last_name image_url bio searchable nsfw tag_string] + profile_data = archive_hash["user"]["profile"]["entity_data"] + convert_keys(profile_data, allowed_keys).tap do |attrs| + attrs[:public_details] = profile_data["public"] + end + end + def import_contacts import_collection(contacts, ContactImporter) end diff --git a/spec/lib/archive_importer_spec.rb b/spec/lib/archive_importer_spec.rb index 495113787..fafe04232 100644 --- a/spec/lib/archive_importer_spec.rb +++ b/spec/lib/archive_importer_spec.rb @@ -119,7 +119,16 @@ describe ArchiveImporter do "user" => { "profile" => { "entity_data" => { - "author" => "old_id@old_pod.nowhere" + "author" => "old_id@old_pod.nowhere", + "first_name" => "First", + "last_name" => "Last", + "full_name" => "Full Name", + "image_url" => "https://example.com/my_avatar.png", + "bio" => "I'm just a test account", + "searchable" => false, + "public" => true, + "nsfw" => true, + "tag_string" => "#diaspora #linux #partying" } }, "email" => "user@example.com", @@ -143,6 +152,15 @@ describe ArchiveImporter do expect(archive_importer.user.language).to eq("ru") expect(archive_importer.user.disable_mail).to eq(false) expect(archive_importer.user.auto_follow_back).to eq(true) + + expect(archive_importer.user.profile.first_name).to eq("First") + expect(archive_importer.user.profile.last_name).to eq("Last") + expect(archive_importer.user.profile.image_url).to eq("https://example.com/my_avatar.png") + expect(archive_importer.user.profile.bio).to eq("I'm just a test account") + expect(archive_importer.user.profile.searchable).to eq(false) + expect(archive_importer.user.profile.public_details).to eq(true) + expect(archive_importer.user.profile.nsfw).to eq(true) + expect(archive_importer.user.profile.tag_string).to eq("#diaspora #linux #partying") end end end