rename target_type to parent_type in relayables
this is equivalent to parent_guid and parent_author_signature also added a validator for parent_type
This commit is contained in:
parent
8bd9c28ce0
commit
08ecfca5d3
18 changed files with 53 additions and 41 deletions
|
|
@ -23,8 +23,8 @@ module DiasporaFederation
|
|||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
|
||||
# The {Comment} parent is a Post
|
||||
# @return [String] target type
|
||||
def target_type
|
||||
# @return [String] parent type
|
||||
def parent_type
|
||||
"Post"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ module DiasporaFederation
|
|||
# @return [String] like guid
|
||||
property :guid
|
||||
|
||||
# @!attribute [r] target_type
|
||||
# A string describing the type of the target.
|
||||
# @!attribute [r] parent_type
|
||||
# A string describing the type of the parent.
|
||||
# Can be "Post" or "Comment" (Comments are currently not implemented in the
|
||||
# Diaspora Frontend).
|
||||
# @return [String] target type
|
||||
property :target_type
|
||||
# @return [String] parent type
|
||||
property :parent_type, xml_name: :target_type
|
||||
|
||||
include Relayable
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ module DiasporaFederation
|
|||
property :conversation_guid
|
||||
|
||||
# The {Message} parent is a {Conversation}
|
||||
# @return [String] target type
|
||||
def target_type
|
||||
# @return [String] parent type
|
||||
def parent_type
|
||||
"Conversation"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ module DiasporaFederation
|
|||
# @return [String] participation guid
|
||||
property :guid
|
||||
|
||||
# @!attribute [r] target_type
|
||||
# @!attribute [r] parent_type
|
||||
# a string describing a type of the target to subscribe on.
|
||||
# currently only "Post" is supported.
|
||||
# @return [String] target type
|
||||
property :target_type
|
||||
# @return [String] parent type
|
||||
property :parent_type, xml_name: :target_type
|
||||
|
||||
include Relayable
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ module DiasporaFederation
|
|||
property :poll_answer_guid
|
||||
|
||||
# The {PollParticipation} parent is a {Poll}
|
||||
# @return [String] target type
|
||||
def target_type
|
||||
# @return [String] parent type
|
||||
def parent_type
|
||||
"Poll"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ module DiasporaFederation
|
|||
|
||||
if parent_author_signature.nil?
|
||||
privkey = DiasporaFederation.callbacks.trigger(
|
||||
:fetch_author_private_key_by_entity_guid, target_type, parent_guid
|
||||
:fetch_author_private_key_by_entity_guid, parent_type, parent_guid
|
||||
)
|
||||
hash[:parent_author_signature] = Signing.sign_with_key(hash, privkey) unless privkey.nil?
|
||||
end
|
||||
|
|
@ -79,7 +79,7 @@ module DiasporaFederation
|
|||
data, author_signature, pubkey
|
||||
)
|
||||
|
||||
author_is_local = DiasporaFederation.callbacks.trigger(:entity_author_is_local?, target_type, parent_guid)
|
||||
author_is_local = DiasporaFederation.callbacks.trigger(:entity_author_is_local?, parent_type, parent_guid)
|
||||
verify_parent_signature unless author_is_local
|
||||
end
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ module DiasporaFederation
|
|||
|
||||
# this happens only on downstream federation
|
||||
def verify_parent_signature
|
||||
pubkey = DiasporaFederation.callbacks.trigger(:fetch_author_public_key_by_entity_guid, target_type, parent_guid)
|
||||
pubkey = DiasporaFederation.callbacks.trigger(:fetch_author_public_key_by_entity_guid, parent_type, parent_guid)
|
||||
|
||||
raise SignatureVerificationFailed, "failed to fetch public key for author of #{parent_guid}" if pubkey.nil?
|
||||
raise SignatureVerificationFailed, "wrong parent_author_signature" unless Signing.verify_signature(
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ module DiasporaFederation
|
|||
factory :participation_entity,
|
||||
class: DiasporaFederation::Entities::Participation, parent: :relayable_entity do
|
||||
guid
|
||||
target_type "Post"
|
||||
parent_type "Post"
|
||||
diaspora_id
|
||||
end
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ module DiasporaFederation
|
|||
factory :like_entity, class: DiasporaFederation::Entities::Like, parent: :relayable_entity do
|
||||
positive true
|
||||
guid
|
||||
target_type "Post"
|
||||
parent_type "Post"
|
||||
diaspora_id
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ module DiasporaFederation
|
|||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :parent_type, [:not_empty, regular_expression: {regex: /\A(Post|Comment)\z/}]
|
||||
|
||||
include RelayableValidator
|
||||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ module DiasporaFederation
|
|||
|
||||
rule :guid, :guid
|
||||
|
||||
rule :target_type, :not_empty
|
||||
rule :parent_type, [:not_empty, regular_expression: {regex: /\APost\z/}]
|
||||
|
||||
include RelayableValidator
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ XML
|
|||
|
||||
it_behaves_like "a relayable Entity"
|
||||
|
||||
describe "#target_type" do
|
||||
it "returns \"Post\" as target type" do
|
||||
expect(described_class.new(data).target_type).to eq("Post")
|
||||
describe "#parent_type" do
|
||||
it "returns \"Post\" as parent type" do
|
||||
expect(described_class.new(data).parent_type).to eq("Post")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ module DiasporaFederation
|
|||
<like>
|
||||
<positive>#{data[:positive]}</positive>
|
||||
<guid>#{data[:guid]}</guid>
|
||||
<target_type>#{data[:target_type]}</target_type>
|
||||
<target_type>#{data[:parent_type]}</target_type>
|
||||
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||
<author_signature>#{data[:author_signature]}</author_signature>
|
||||
|
|
@ -22,9 +22,9 @@ XML
|
|||
|
||||
it_behaves_like "a relayable Entity"
|
||||
|
||||
describe "#target_type" do
|
||||
it "returns data[:target_type] as target type" do
|
||||
expect(described_class.new(data).target_type).to eq(data[:target_type])
|
||||
describe "#parent_type" do
|
||||
it "returns data[:parent_type] as parent type" do
|
||||
expect(described_class.new(data).parent_type).to eq(data[:parent_type])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ XML
|
|||
|
||||
it_behaves_like "a relayable Entity"
|
||||
|
||||
describe "#target_type" do
|
||||
it "returns \"Conversation\" as target type" do
|
||||
expect(described_class.new(data).target_type).to eq("Conversation")
|
||||
describe "#parent_type" do
|
||||
it "returns \"Conversation\" as parent type" do
|
||||
expect(described_class.new(data).parent_type).to eq("Conversation")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ module DiasporaFederation
|
|||
<<-XML
|
||||
<participation>
|
||||
<guid>#{data[:guid]}</guid>
|
||||
<target_type>#{data[:target_type]}</target_type>
|
||||
<target_type>#{data[:parent_type]}</target_type>
|
||||
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||
<author_signature>#{data[:author_signature]}</author_signature>
|
||||
|
|
@ -21,9 +21,9 @@ XML
|
|||
|
||||
it_behaves_like "a relayable Entity"
|
||||
|
||||
describe "#target_type" do
|
||||
it "returns data[:target_type] as target type" do
|
||||
expect(described_class.new(data).target_type).to eq(data[:target_type])
|
||||
describe "#parent_type" do
|
||||
it "returns data[:parent_type] as parent type" do
|
||||
expect(described_class.new(data).parent_type).to eq(data[:parent_type])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ XML
|
|||
|
||||
it_behaves_like "a relayable Entity"
|
||||
|
||||
describe "#target_type" do
|
||||
it "returns \"Poll\" as target type" do
|
||||
expect(described_class.new(data).target_type).to eq("Poll")
|
||||
describe "#parent_type" do
|
||||
it "returns \"Poll\" as parent type" do
|
||||
expect(described_class.new(data).parent_type).to eq("Poll")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ module DiasporaFederation
|
|||
|
||||
property :diaspora_id, xml_name: :diaspora_handle
|
||||
|
||||
def target_type
|
||||
def parent_type
|
||||
"Target"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,5 +15,13 @@ module DiasporaFederation
|
|||
let(:property) { :diaspora_id }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
describe "#parent_type" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :parent_type }
|
||||
let(:wrong_values) { [nil, "", "any", "Postxxx", "post"] }
|
||||
let(:correct_values) { %w(Post Comment) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,9 +17,11 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
describe "#target_type" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { :target_type }
|
||||
describe "#parent_type" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
let(:property) { :parent_type }
|
||||
let(:wrong_values) { [nil, "", "any", "Postxxx", "post"] }
|
||||
let(:correct_values) { ["Post"] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ module DiasporaFederation
|
|||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
describe "#type" do
|
||||
describe "#target_type" do
|
||||
it_behaves_like "a property that mustn't be empty" do
|
||||
let(:property) { :target_type }
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue