Remove public and provider_display_name from reshare entity
Also don't extend from Post module anymore to represent the future state of a reshare as it's own type only used to increase the reach of a post. See #83
This commit is contained in:
parent
0b07b36017
commit
b1b511b6f7
6 changed files with 40 additions and 57 deletions
|
|
@ -4,7 +4,22 @@ module DiasporaFederation
|
||||||
#
|
#
|
||||||
# @see Validators::ReshareValidator
|
# @see Validators::ReshareValidator
|
||||||
class Reshare < Entity
|
class Reshare < Entity
|
||||||
include Post
|
# @!attribute [r] author
|
||||||
|
# The diaspora* ID of the person who reshares the post
|
||||||
|
# @see Person#author
|
||||||
|
# @return [String] diaspora* ID
|
||||||
|
property :author, :string, xml_name: :diaspora_handle
|
||||||
|
|
||||||
|
# @!attribute [r] guid
|
||||||
|
# A random string of at least 16 chars
|
||||||
|
# @see Validation::Rule::Guid
|
||||||
|
# @return [String] status message guid
|
||||||
|
property :guid, :string
|
||||||
|
|
||||||
|
# @!attribute [r] created_at
|
||||||
|
# Post entity creation time
|
||||||
|
# @return [Time] creation time
|
||||||
|
property :created_at, :timestamp, default: -> { Time.now.utc }
|
||||||
|
|
||||||
# @!attribute [r] root_author
|
# @!attribute [r] root_author
|
||||||
# The diaspora* ID of the person who posted the original post
|
# The diaspora* ID of the person who posted the original post
|
||||||
|
|
@ -18,11 +33,6 @@ module DiasporaFederation
|
||||||
# @return [String] root guid
|
# @return [String] root guid
|
||||||
property :root_guid, :string, optional: true
|
property :root_guid, :string, optional: true
|
||||||
|
|
||||||
# @!attribute [r] public
|
|
||||||
# Has no meaning at the moment
|
|
||||||
# @return [Boolean] public
|
|
||||||
property :public, :boolean, optional: true, default: true # always true? (we only reshare public posts)
|
|
||||||
|
|
||||||
# @return [String] string representation of this object
|
# @return [String] string representation of this object
|
||||||
def to_s
|
def to_s
|
||||||
"#{super}:#{root_guid}"
|
"#{super}:#{root_guid}"
|
||||||
|
|
@ -30,6 +40,11 @@ module DiasporaFederation
|
||||||
|
|
||||||
# Fetch and receive root post from remote, if not available locally
|
# Fetch and receive root post from remote, if not available locally
|
||||||
# and validates if it's from the correct author
|
# and validates if it's from the correct author
|
||||||
|
# TODO: after reshares are only used to increase the reach of a post (and
|
||||||
|
# legacy reshares with own interactions are migrated to the new form),
|
||||||
|
# root_author and root_guid aren't allowed to be empty anymore, so a
|
||||||
|
# not_nil check should be added to the validator and the first few lines
|
||||||
|
# here can be removed.
|
||||||
def validate_root
|
def validate_root
|
||||||
return if root_author.nil? && root_guid.nil?
|
return if root_author.nil? && root_guid.nil?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,28 +215,26 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"reshare": {
|
"reshare": {
|
||||||
"allOf": [
|
"type": "object",
|
||||||
{"$ref": "#/definitions/post"},
|
"properties": {
|
||||||
{
|
"entity_type": {
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "^reshare$"
|
||||||
|
},
|
||||||
|
|
||||||
|
"entity_data": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"entity_type": {
|
"author": { "type": "string" },
|
||||||
"type": "string",
|
"guid": { "$ref": "#/definitions/guid" },
|
||||||
"pattern": "^reshare$"
|
"created_at": { "type": "string" },
|
||||||
},
|
"root_author": {"type": "string"},
|
||||||
|
"root_guid": {"$ref": "#/definitions/guid"}
|
||||||
"entity_data": {
|
},
|
||||||
"type": "object",
|
"required": ["author", "guid", "created_at", "root_author", "root_guid"]
|
||||||
"properties": {
|
},
|
||||||
"root_author": {"type": "string"},
|
"required": ["entity_type", "entity_data"]
|
||||||
"root_guid": {"$ref": "#/definitions/guid"}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
"required": ["root_author", "root_guid"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"profile": {
|
"profile": {
|
||||||
|
|
|
||||||
|
|
@ -150,9 +150,7 @@ module DiasporaFederation
|
||||||
root_guid { Fabricate.sequence(:guid) }
|
root_guid { Fabricate.sequence(:guid) }
|
||||||
guid { Fabricate.sequence(:guid) }
|
guid { Fabricate.sequence(:guid) }
|
||||||
author { Fabricate.sequence(:diaspora_id) }
|
author { Fabricate.sequence(:diaspora_id) }
|
||||||
public true
|
|
||||||
created_at { Time.now.utc }
|
created_at { Time.now.utc }
|
||||||
provider_display_name { "the testsuite" }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:retraction_entity, class_name: DiasporaFederation::Entities::Retraction) do
|
Fabricator(:retraction_entity, class_name: DiasporaFederation::Entities::Retraction) do
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ module DiasporaFederation
|
||||||
rule :author, %i[not_empty diaspora_id]
|
rule :author, %i[not_empty diaspora_id]
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :public, :boolean
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,8 @@ module DiasporaFederation
|
||||||
<author>#{data[:author]}</author>
|
<author>#{data[:author]}</author>
|
||||||
<guid>#{data[:guid]}</guid>
|
<guid>#{data[:guid]}</guid>
|
||||||
<created_at>#{data[:created_at].utc.iso8601}</created_at>
|
<created_at>#{data[:created_at].utc.iso8601}</created_at>
|
||||||
<provider_display_name>#{data[:provider_display_name]}</provider_display_name>
|
|
||||||
<root_author>#{data[:root_author]}</root_author>
|
<root_author>#{data[:root_author]}</root_author>
|
||||||
<root_guid>#{data[:root_guid]}</root_guid>
|
<root_guid>#{data[:root_guid]}</root_guid>
|
||||||
<public>#{data[:public]}</public>
|
|
||||||
</reshare>
|
</reshare>
|
||||||
XML
|
XML
|
||||||
|
|
||||||
|
|
@ -22,10 +20,8 @@ XML
|
||||||
"author": "#{data[:author]}",
|
"author": "#{data[:author]}",
|
||||||
"guid": "#{data[:guid]}",
|
"guid": "#{data[:guid]}",
|
||||||
"created_at": "#{data[:created_at].utc.iso8601}",
|
"created_at": "#{data[:created_at].utc.iso8601}",
|
||||||
"provider_display_name": "#{data[:provider_display_name]}",
|
|
||||||
"root_author": "#{data[:root_author]}",
|
"root_author": "#{data[:root_author]}",
|
||||||
"root_guid": "#{data[:root_guid]}",
|
"root_guid": "#{data[:root_guid]}"
|
||||||
"public": #{data[:public]}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JSON
|
JSON
|
||||||
|
|
@ -38,24 +34,6 @@ JSON
|
||||||
|
|
||||||
it_behaves_like "a JSON Entity"
|
it_behaves_like "a JSON Entity"
|
||||||
|
|
||||||
context "default values" do
|
|
||||||
it "uses default values" do
|
|
||||||
minimal_xml = <<-XML
|
|
||||||
<reshare>
|
|
||||||
<author>#{data[:author]}</author>
|
|
||||||
<guid>#{data[:guid]}</guid>
|
|
||||||
<created_at>#{data[:created_at]}</created_at>
|
|
||||||
<root_diaspora_id>#{data[:root_author]}</root_diaspora_id>
|
|
||||||
<root_guid>#{data[:root_guid]}</root_guid>
|
|
||||||
</reshare>
|
|
||||||
XML
|
|
||||||
|
|
||||||
parsed_instance = DiasporaFederation::Salmon::XmlPayload.unpack(Nokogiri::XML(minimal_xml).root)
|
|
||||||
expect(parsed_instance.public).to be_truthy
|
|
||||||
expect(parsed_instance.provider_display_name).to be_nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "parse xml" do
|
context "parse xml" do
|
||||||
describe "#validate_root" do
|
describe "#validate_root" do
|
||||||
it "fetches the root post if it is not available already" do
|
it "fetches the root post if it is not available already" do
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,5 @@ module DiasporaFederation
|
||||||
let(:mandatory) { false }
|
let(:mandatory) { false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "a boolean validator" do
|
|
||||||
let(:property) { :public }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue