From cce2c7fe3199fe2d1038041be6997e623a88baad Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 9 Apr 2018 00:50:39 +0200 Subject: [PATCH] Add full_name to profile This is needed for diaspora/diaspora#3648 --- docs/_entities/profile.md | 2 ++ lib/diaspora_federation/entities/profile.rb | 4 ++++ lib/diaspora_federation/schemas/federation_entities.json | 1 + lib/diaspora_federation/test/factories.rb | 1 + lib/diaspora_federation/validators/profile_validator.rb | 1 + .../diaspora_federation/entities/account_migration_spec.rb | 3 +++ spec/lib/diaspora_federation/entities/person_spec.rb | 1 + spec/lib/diaspora_federation/entities/profile_spec.rb | 3 +++ .../validators/profile_validator_spec.rb | 7 +++++++ 9 files changed, 23 insertions(+) diff --git a/docs/_entities/profile.md b/docs/_entities/profile.md index 78408d8..98065b5 100644 --- a/docs/_entities/profile.md +++ b/docs/_entities/profile.md @@ -30,6 +30,7 @@ only contain the base profile. | Property | Type (Length) | Editable | Description | | ------------------ | ---------------------------- |:--------:| -------------------------------------------------------------------------------------------------------- | | `edited_at` | [Timestamp][timestamp] | ✔ | The timestamp when the profile was edited. | +| `full_name` | [Name][name] (70) | ✔ | The full name of the person. | | `first_name` | [Name][name] (32) | ✔ | The first name of the person. | | `last_name` | [Name][name] (32) | ✔ | The last name of the person. | | `image_url` | [URL][url] (255) | ✔ | The URL to the big avatar (300x300) of the person. | @@ -50,6 +51,7 @@ only contain the base profile. alice@example.org 2018-01-23T01:19:56Z + Alice Smith Alice Smith https://example.org/images/thumb_large_a795f872c93309597345.jpg diff --git a/lib/diaspora_federation/entities/profile.rb b/lib/diaspora_federation/entities/profile.rb index 80edbae..ea851b1 100644 --- a/lib/diaspora_federation/entities/profile.rb +++ b/lib/diaspora_federation/entities/profile.rb @@ -19,6 +19,10 @@ module DiasporaFederation # @return [Time] edited time property :edited_at, :timestamp, optional: true + # @!attribute [r] full_name + # @return [String] display name of the user + property :full_name, :string, optional: true + # @!attribute [r] first_name # @deprecated We decided to only use one name field, these should be removed # in later iterations (will affect older diaspora* installations). diff --git a/lib/diaspora_federation/schemas/federation_entities.json b/lib/diaspora_federation/schemas/federation_entities.json index b30af83..3bf0501 100644 --- a/lib/diaspora_federation/schemas/federation_entities.json +++ b/lib/diaspora_federation/schemas/federation_entities.json @@ -247,6 +247,7 @@ "entity_data": { "type": "object", "properties": { + "full_name": { "type": ["string", "null"] }, "first_name": { "type": ["string", "null"] }, "last_name": { "type": ["string", "null"] }, "gender": { "type": ["string", "null"] }, diff --git a/lib/diaspora_federation/test/factories.rb b/lib/diaspora_federation/test/factories.rb index 24433a1..40744fb 100644 --- a/lib/diaspora_federation/test/factories.rb +++ b/lib/diaspora_federation/test/factories.rb @@ -56,6 +56,7 @@ module DiasporaFederation Fabricator(:profile_entity, class_name: DiasporaFederation::Entities::Profile) do author { Fabricate.sequence(:diaspora_id) } edited_at { Time.now.utc } + full_name "my name" first_name "my name" last_name nil image_url "/assets/user/default.png" diff --git a/lib/diaspora_federation/validators/profile_validator.rb b/lib/diaspora_federation/validators/profile_validator.rb index 5d881aa..38ef3e3 100644 --- a/lib/diaspora_federation/validators/profile_validator.rb +++ b/lib/diaspora_federation/validators/profile_validator.rb @@ -8,6 +8,7 @@ module DiasporaFederation # The name must not contain a semicolon because of mentions. # @{ ; } + rule :full_name, regular_expression: {regex: /\A[^;]{,70}\z/} rule :first_name, regular_expression: {regex: /\A[^;]{,32}\z/} rule :last_name, regular_expression: {regex: /\A[^;]{,32}\z/} diff --git a/spec/lib/diaspora_federation/entities/account_migration_spec.rb b/spec/lib/diaspora_federation/entities/account_migration_spec.rb index 1f6ce00..37852df 100644 --- a/spec/lib/diaspora_federation/entities/account_migration_spec.rb +++ b/spec/lib/diaspora_federation/entities/account_migration_spec.rb @@ -110,6 +110,7 @@ module DiasporaFederation #{data[:author]} #{data[:profile].author} + #{data[:profile].full_name} #{data[:profile].first_name} #{data[:profile].image_url} #{data[:profile].image_url} @@ -148,6 +149,7 @@ XML #{data[:author]} #{data[:profile].author} + #{data[:profile].full_name} #{data[:profile].first_name} #{data[:profile].image_url} #{data[:profile].image_url} @@ -185,6 +187,7 @@ XML #{data[:author]} #{data[:profile].author} + #{data[:profile].full_name} #{data[:profile].first_name} #{data[:profile].image_url} #{data[:profile].image_url} diff --git a/spec/lib/diaspora_federation/entities/person_spec.rb b/spec/lib/diaspora_federation/entities/person_spec.rb index 69aadb3..615a41e 100644 --- a/spec/lib/diaspora_federation/entities/person_spec.rb +++ b/spec/lib/diaspora_federation/entities/person_spec.rb @@ -10,6 +10,7 @@ module DiasporaFederation #{data[:profile].author} #{data[:profile].edited_at.utc.iso8601} + #{data[:profile].full_name} #{data[:profile].first_name} #{data[:profile].image_url} #{data[:profile].image_url} diff --git a/spec/lib/diaspora_federation/entities/profile_spec.rb b/spec/lib/diaspora_federation/entities/profile_spec.rb index 682353e..fa42faf 100644 --- a/spec/lib/diaspora_federation/entities/profile_spec.rb +++ b/spec/lib/diaspora_federation/entities/profile_spec.rb @@ -6,6 +6,7 @@ module DiasporaFederation #{data[:author]} #{data[:edited_at].utc.iso8601} + #{data[:full_name]} #{data[:first_name]} #{data[:image_url]} #{data[:image_url]} @@ -27,6 +28,7 @@ XML "entity_data": { "author": "#{data[:author]}", "edited_at": "#{data[:edited_at].iso8601}", + "full_name": "#{data[:full_name]}", "first_name": "#{data[:first_name]}", "image_url": "#{data[:image_url]}", "image_url_medium": "#{data[:image_url]}", @@ -60,6 +62,7 @@ JSON XML parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML(minimal_xml).root) + expect(parsed_instance.full_name).to be_nil expect(parsed_instance.first_name).to be_nil expect(parsed_instance.last_name).to be_nil expect(parsed_instance.image_url).to be_nil diff --git a/spec/lib/diaspora_federation/validators/profile_validator_spec.rb b/spec/lib/diaspora_federation/validators/profile_validator_spec.rb index 5f8b52c..c9c4e7c 100644 --- a/spec/lib/diaspora_federation/validators/profile_validator_spec.rb +++ b/spec/lib/diaspora_federation/validators/profile_validator_spec.rb @@ -8,6 +8,13 @@ module DiasporaFederation let(:property) { :author } end + describe "#full_name" do + it_behaves_like "a name validator" do + let(:property) { :full_name } + let(:length) { 70 } + end + end + %i[first_name last_name].each do |prop| describe "##{prop}" do it_behaves_like "a name validator" do