Account import: import profile data too
This commit is contained in:
parent
bffe2b651c
commit
f7324adb9c
2 changed files with 31 additions and 2 deletions
|
|
@ -28,7 +28,10 @@ class ArchiveImporter
|
||||||
data.merge!(
|
data.merge!(
|
||||||
username: attr[:username],
|
username: attr[:username],
|
||||||
password: attr[:password],
|
password: attr[:password],
|
||||||
password_confirmation: attr[:password]
|
password_confirmation: attr[:password],
|
||||||
|
person: {
|
||||||
|
profile_attributes: profile_attributes
|
||||||
|
}
|
||||||
)
|
)
|
||||||
self.user = User.build(data)
|
self.user = User.build(data)
|
||||||
user.save!
|
user.save!
|
||||||
|
|
@ -38,6 +41,14 @@ class ArchiveImporter
|
||||||
|
|
||||||
attr_reader :archive_hash
|
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
|
def import_contacts
|
||||||
import_collection(contacts, ContactImporter)
|
import_collection(contacts, ContactImporter)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,16 @@ describe ArchiveImporter do
|
||||||
"user" => {
|
"user" => {
|
||||||
"profile" => {
|
"profile" => {
|
||||||
"entity_data" => {
|
"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",
|
"email" => "user@example.com",
|
||||||
|
|
@ -143,6 +152,15 @@ describe ArchiveImporter do
|
||||||
expect(archive_importer.user.language).to eq("ru")
|
expect(archive_importer.user.language).to eq("ru")
|
||||||
expect(archive_importer.user.disable_mail).to eq(false)
|
expect(archive_importer.user.disable_mail).to eq(false)
|
||||||
expect(archive_importer.user.auto_follow_back).to eq(true)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue