add string representation to entities for better and easier logging
This commit is contained in:
parent
58b22df9c5
commit
38922d5f30
36 changed files with 86 additions and 3 deletions
|
|
@ -175,6 +175,11 @@ module DiasporaFederation
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"WebFinger:#{acct_uri}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Parses the XML string to a Hash and does some rudimentary checking on
|
# Parses the XML string to a Hash and does some rudimentary checking on
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,11 @@ module DiasporaFederation
|
||||||
# @see AccountDeletion#author
|
# @see AccountDeletion#author
|
||||||
# @return [String] diaspora ID
|
# @return [String] diaspora ID
|
||||||
property :author, alias: :diaspora_id, xml_name: :diaspora_handle
|
property :author, alias: :diaspora_id, xml_name: :diaspora_handle
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"AccountDeletion:#{author}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ module DiasporaFederation
|
||||||
# @!attribute [r] sharing
|
# @!attribute [r] sharing
|
||||||
# @return [Boolean] if the author is sharing with the person
|
# @return [Boolean] if the author is sharing with the person
|
||||||
property :sharing, default: true
|
property :sharing, default: true
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"Contact:#{author}:#{recipient}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ module DiasporaFederation
|
||||||
|
|
||||||
property :nsfw, default: false
|
property :nsfw, default: false
|
||||||
property :tag_string, default: nil
|
property :tag_string, default: nil
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"Profile:#{author}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,11 @@ module DiasporaFederation
|
||||||
sender == author || sender == parent.author
|
sender == author || sender == parent.author
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"#{super}#{":#{parent_type}" if respond_to?(:parent_type)}:#{parent_guid}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# this happens only on downstream federation
|
# this happens only on downstream federation
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,11 @@ module DiasporaFederation
|
||||||
Retraction.new(author: author, target_guid: target_guid, target_type: target_type, target: target)
|
Retraction.new(author: author, target_guid: target_guid, target_type: target_type, target: target)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"RelayableRetraction:#{target_type}:#{target_guid}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# @param [Nokogiri::XML::Element] root_node xml nodes
|
# @param [Nokogiri::XML::Element] root_node xml nodes
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ module DiasporaFederation
|
||||||
Contact.new(author: author, recipient: recipient)
|
Contact.new(author: author, recipient: recipient)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"Request:#{author}:#{recipient}"
|
||||||
|
end
|
||||||
|
|
||||||
# @param [Nokogiri::XML::Element] root_node xml nodes
|
# @param [Nokogiri::XML::Element] root_node xml nodes
|
||||||
# @return [Retraction] instance
|
# @return [Retraction] instance
|
||||||
def self.populate_entity(root_node)
|
def self.populate_entity(root_node)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,11 @@ module DiasporaFederation
|
||||||
# has no meaning at the moment
|
# has no meaning at the moment
|
||||||
# @return [Boolean] public
|
# @return [Boolean] public
|
||||||
property :public, default: true # always true? (we only reshare public posts)
|
property :public, default: true # always true? (we only reshare public posts)
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"#{super}:#{root_guid}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"Retraction:#{target_type}:#{target_guid}"
|
||||||
|
end
|
||||||
|
|
||||||
# @param [Nokogiri::XML::Element] root_node xml nodes
|
# @param [Nokogiri::XML::Element] root_node xml nodes
|
||||||
# @return [Retraction] instance
|
# @return [Retraction] instance
|
||||||
def self.populate_entity(root_node)
|
def self.populate_entity(root_node)
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,11 @@ module DiasporaFederation
|
||||||
Base64.strict_encode64(privkey.sign(Relayable::DIGEST, [ret.target_guid, ret.target_type].join(";")))
|
Base64.strict_encode64(privkey.sign(Relayable::DIGEST, [ret.target_guid, ret.target_type].join(";")))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"SignedRetraction:#{target_type}:#{target_guid}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# @param [Nokogiri::XML::Element] root_node xml nodes
|
# @param [Nokogiri::XML::Element] root_node xml nodes
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,11 @@ module DiasporaFederation
|
||||||
Entities.const_get(class_name)
|
Entities.const_get(class_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String] string representation of this object
|
||||||
|
def to_s
|
||||||
|
"#{self.class.name.rpartition('::').last}#{":#{guid}" if respond_to?(:guid)}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def setable?(name, val)
|
def setable?(name, val)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ module DiasporaFederation
|
||||||
def receive
|
def receive
|
||||||
validate_and_receive
|
validate_and_receive
|
||||||
rescue => e
|
rescue => e
|
||||||
logger.error "failed to receive #{entity.class}#{":#{entity.guid}" if entity.respond_to?(:guid)}"
|
logger.error "failed to receive #{entity}"
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -29,8 +29,7 @@ module DiasporaFederation
|
||||||
def validate_and_receive
|
def validate_and_receive
|
||||||
validate
|
validate
|
||||||
DiasporaFederation.callbacks.trigger(:receive_entity, entity, recipient_id)
|
DiasporaFederation.callbacks.trigger(:receive_entity, entity, recipient_id)
|
||||||
logger.info "successfully received #{entity.class}#{":#{entity.guid}" if entity.respond_to?(:guid)} " \
|
logger.info "successfully received #{entity} from person #{sender}#{" for #{recipient_id}" if recipient_id}"
|
||||||
"from person #{sender}#{" for #{recipient_id}" if recipient_id}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ module DiasporaFederation
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
}
|
}
|
||||||
|
let(:string) { "HCard:#{data[:guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ module DiasporaFederation
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "WebFinger:#{data[:acct_uri]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ module DiasporaFederation
|
||||||
</account_deletion>
|
</account_deletion>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "AccountDeletion:#{data[:author]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ module DiasporaFederation
|
||||||
</comment>
|
</comment>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Comment:#{data[:guid]}:#{parent.guid}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass", [:parent]
|
it_behaves_like "an Entity subclass", [:parent]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ module DiasporaFederation
|
||||||
</contact>
|
</contact>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Contact:#{data[:author]}:#{data[:recipient]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ module DiasporaFederation
|
||||||
</conversation>
|
</conversation>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Conversation:#{data[:guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ module DiasporaFederation
|
||||||
</like>
|
</like>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Like:#{data[:guid]}:Post:#{parent.guid}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass", [:parent]
|
it_behaves_like "an Entity subclass", [:parent]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ module DiasporaFederation
|
||||||
</location>
|
</location>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Location" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ module DiasporaFederation
|
||||||
</message>
|
</message>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Message:#{data[:guid]}:#{parent.guid}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass", [:parent]
|
it_behaves_like "an Entity subclass", [:parent]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ module DiasporaFederation
|
||||||
</participation>
|
</participation>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Participation:#{data[:guid]}:Post:#{parent.guid}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass", [:parent]
|
it_behaves_like "an Entity subclass", [:parent]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ module DiasporaFederation
|
||||||
</person>
|
</person>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Person:#{data[:guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ module DiasporaFederation
|
||||||
</photo>
|
</photo>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Photo:#{data[:guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ module DiasporaFederation
|
||||||
</poll_answer>
|
</poll_answer>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "PollAnswer:#{data[:guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ module DiasporaFederation
|
||||||
</poll_participation>
|
</poll_participation>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "PollParticipation:#{data[:guid]}:#{parent.guid}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass", [:parent]
|
it_behaves_like "an Entity subclass", [:parent]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ module DiasporaFederation
|
||||||
</poll>
|
</poll>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Poll:#{data[:guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ module DiasporaFederation
|
||||||
</profile>
|
</profile>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Profile:#{data[:author]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe Entities::RelatedEntity do
|
describe Entities::RelatedEntity do
|
||||||
let(:data) { FactoryGirl.attributes_for(:related_entity) }
|
let(:data) { FactoryGirl.attributes_for(:related_entity) }
|
||||||
|
let(:string) { "RelatedEntity" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ module DiasporaFederation
|
||||||
</relayable_retraction>
|
</relayable_retraction>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "RelayableRetraction:#{data[:target_type]}:#{data[:target_guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass", [:target]
|
it_behaves_like "an Entity subclass", [:target]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ module DiasporaFederation
|
||||||
</request>
|
</request>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Request:#{data[:author]}:#{data[:recipient]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ module DiasporaFederation
|
||||||
</reshare>
|
</reshare>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Reshare:#{data[:guid]}:#{data[:root_guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ module DiasporaFederation
|
||||||
</retraction>
|
</retraction>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "Retraction:#{data[:target_type]}:#{data[:target_guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass", [:target]
|
it_behaves_like "an Entity subclass", [:target]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ module DiasporaFederation
|
||||||
</signed_retraction>
|
</signed_retraction>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "SignedRetraction:#{data[:target_type]}:#{data[:target_guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass", [:target]
|
it_behaves_like "an Entity subclass", [:target]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ module DiasporaFederation
|
||||||
</status_message>
|
</status_message>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
let(:string) { "StatusMessage:#{data[:guid]}" }
|
||||||
|
|
||||||
it_behaves_like "an Entity subclass"
|
it_behaves_like "an Entity subclass"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@ shared_examples "an Entity subclass" do |ignored_props=[]|
|
||||||
expect(hash).to eq(data)
|
expect(hash).to eq(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#to_s" do
|
||||||
|
it "should represent the entity as string" do
|
||||||
|
expect(instance.to_s).to eq(string)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue