Skip to content

Commit

Permalink
Merge pull request #100 from SuperTux88/add-full_name
Browse files Browse the repository at this point in the history
Add full_name to profile
  • Loading branch information
SuperTux88 committed Jun 17, 2018
2 parents 3f08152 + cce2c7f commit 512fafb
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/_entities/profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -50,6 +51,7 @@ only contain the base profile.
<profile>
<author>alice@example.org</author>
<edited_at>2018-01-23T01:19:56Z</edited_at>
<full_name>Alice Smith</full_name>
<first_name>Alice</first_name>
<last_name>Smith</last_name>
<image_url>https://example.org/images/thumb_large_a795f872c93309597345.jpg</image_url>
Expand Down
4 changes: 4 additions & 0 deletions lib/diaspora_federation/entities/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Profile < Entity
# @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).
Expand Down
1 change: 1 addition & 0 deletions lib/diaspora_federation/schemas/federation_entities.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"] },
Expand Down
1 change: 1 addition & 0 deletions lib/diaspora_federation/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module Factories
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"
Expand Down
1 change: 1 addition & 0 deletions lib/diaspora_federation/validators/profile_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ProfileValidator < OptionalAwareValidator

# The name must not contain a semicolon because of mentions.
# @{<full_name> ; <diaspora_id>}
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/}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module DiasporaFederation
<author>#{data[:author]}</author>
<profile>
<author>#{data[:profile].author}</author>
<full_name>#{data[:profile].full_name}</full_name>
<first_name>#{data[:profile].first_name}</first_name>
<image_url>#{data[:profile].image_url}</image_url>
<image_url_medium>#{data[:profile].image_url}</image_url_medium>
Expand Down Expand Up @@ -148,6 +149,7 @@ module DiasporaFederation
<author>#{data[:author]}</author>
<profile>
<author>#{data[:profile].author}</author>
<full_name>#{data[:profile].full_name}</full_name>
<first_name>#{data[:profile].first_name}</first_name>
<image_url>#{data[:profile].image_url}</image_url>
<image_url_medium>#{data[:profile].image_url}</image_url_medium>
Expand Down Expand Up @@ -185,6 +187,7 @@ module DiasporaFederation
<author>#{data[:author]}</author>
<profile>
<author>#{data[:profile].author}</author>
<full_name>#{data[:profile].full_name}</full_name>
<first_name>#{data[:profile].first_name}</first_name>
<image_url>#{data[:profile].image_url}</image_url>
<image_url_medium>#{data[:profile].image_url}</image_url_medium>
Expand Down
1 change: 1 addition & 0 deletions spec/lib/diaspora_federation/entities/person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module DiasporaFederation
<profile>
<author>#{data[:profile].author}</author>
<edited_at>#{data[:profile].edited_at.utc.iso8601}</edited_at>
<full_name>#{data[:profile].full_name}</full_name>
<first_name>#{data[:profile].first_name}</first_name>
<image_url>#{data[:profile].image_url}</image_url>
<image_url_medium>#{data[:profile].image_url}</image_url_medium>
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/diaspora_federation/entities/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module DiasporaFederation
<profile>
<author>#{data[:author]}</author>
<edited_at>#{data[:edited_at].utc.iso8601}</edited_at>
<full_name>#{data[:full_name]}</full_name>
<first_name>#{data[:first_name]}</first_name>
<image_url>#{data[:image_url]}</image_url>
<image_url_medium>#{data[:image_url]}</image_url_medium>
Expand All @@ -27,6 +28,7 @@ module DiasporaFederation
"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]}",
Expand Down Expand Up @@ -60,6 +62,7 @@ module DiasporaFederation
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 512fafb

Please sign in to comment.