rename xml_elements to enriched_properties
This commit is contained in:
parent
bc7f0219c8
commit
3e8534c5c4
12 changed files with 28 additions and 23 deletions
|
|
@ -151,11 +151,11 @@ module DiasporaFederation
|
||||||
# if the signatures are not there yet and if the keys are available.
|
# if the signatures are not there yet and if the keys are available.
|
||||||
#
|
#
|
||||||
# @return [Hash] sorted xml elements with updated signatures
|
# @return [Hash] sorted xml elements with updated signatures
|
||||||
def xml_elements
|
def enriched_properties
|
||||||
xml_data = super.merge(additional_xml_elements)
|
data = super.merge(additional_xml_elements)
|
||||||
signature_order.map {|element| [element, xml_data[element] || ""] }.to_h.tap do |xml_elements|
|
signature_order.map {|element| [element, data[element] || ""] }.to_h.tap do |hash|
|
||||||
xml_elements[:author_signature] = author_signature || sign_with_author
|
hash[:author_signature] = author_signature || sign_with_author
|
||||||
xml_elements[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
|
hash[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -172,7 +172,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
# @return [String] signature data string
|
# @return [String] signature data string
|
||||||
def signature_data
|
def signature_data
|
||||||
data = to_h.merge(additional_xml_elements)
|
data = normalized_properties.merge(additional_xml_elements)
|
||||||
signature_order.map {|name| data[name] }.join(";")
|
signature_order.map {|name| data[name] }.join(";")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,11 +83,11 @@ module DiasporaFederation
|
||||||
# if the signatures are not there yet and if the keys are available.
|
# if the signatures are not there yet and if the keys are available.
|
||||||
#
|
#
|
||||||
# @return [Hash] xml elements with updated signatures
|
# @return [Hash] xml elements with updated signatures
|
||||||
def xml_elements
|
def enriched_properties
|
||||||
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
|
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
|
||||||
|
|
||||||
super.tap do |xml_elements|
|
super.tap do |hash|
|
||||||
fill_required_signature(privkey, xml_elements) unless privkey.nil?
|
fill_required_signature(privkey, hash) unless privkey.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,9 @@ module DiasporaFederation
|
||||||
# if the signatures are not there yet and if the keys are available.
|
# if the signatures are not there yet and if the keys are available.
|
||||||
#
|
#
|
||||||
# @return [Hash] xml elements with updated signatures
|
# @return [Hash] xml elements with updated signatures
|
||||||
def xml_elements
|
def enriched_properties
|
||||||
super.tap do |xml_elements|
|
super.tap do |hash|
|
||||||
xml_elements[:target_author_signature] = target_author_signature || sign_with_author.to_s
|
hash[:target_author_signature] = target_author_signature || sign_with_author.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ module DiasporaFederation
|
||||||
def to_xml
|
def to_xml
|
||||||
doc = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new)
|
doc = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new)
|
||||||
Nokogiri::XML::Element.new(self.class.entity_name, doc).tap do |root_element|
|
Nokogiri::XML::Element.new(self.class.entity_name, doc).tap do |root_element|
|
||||||
xml_elements.each do |name, value|
|
enriched_properties.each do |name, value|
|
||||||
add_property_to_xml(doc, root_element, name, value)
|
add_property_to_xml(doc, root_element, name, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -215,10 +215,15 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def xml_elements
|
def normalized_properties
|
||||||
properties.map {|name, value| [name, self.class.class_props[name] == String ? value.to_s : value] }.to_h
|
properties.map {|name, value| [name, self.class.class_props[name] == String ? value.to_s : value] }.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# default: nothing to enrich
|
||||||
|
def enriched_properties
|
||||||
|
normalized_properties
|
||||||
|
end
|
||||||
|
|
||||||
def add_property_to_xml(doc, root_element, name, value)
|
def add_property_to_xml(doc, root_element, name, value)
|
||||||
if value.is_a? String
|
if value.is_a? String
|
||||||
root_element << simple_node(doc, name, value)
|
root_element << simple_node(doc, name, value)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
|
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
|
||||||
let(:data) {
|
let(:data) {
|
||||||
FactoryGirl.build(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
FactoryGirl.build(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
||||||
.send(:xml_elements).merge(created_at: Time.now.utc, parent: parent_entity)
|
.send(:enriched_properties).merge(created_at: Time.now.utc, parent: parent_entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:xml) { <<-XML }
|
let(:xml) { <<-XML }
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ module DiasporaFederation
|
||||||
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
|
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
|
||||||
let(:signed_msg1) {
|
let(:signed_msg1) {
|
||||||
FactoryGirl.build(:message_entity, author: bob.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
FactoryGirl.build(:message_entity, author: bob.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
||||||
.send(:xml_elements).merge(parent: parent_entity)
|
.send(:enriched_properties).merge(parent: parent_entity)
|
||||||
}
|
}
|
||||||
let(:signed_msg2) {
|
let(:signed_msg2) {
|
||||||
FactoryGirl.build(:message_entity, author: bob.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
FactoryGirl.build(:message_entity, author: bob.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
||||||
.send(:xml_elements).merge(parent: parent_entity)
|
.send(:enriched_properties).merge(parent: parent_entity)
|
||||||
}
|
}
|
||||||
let(:data) {
|
let(:data) {
|
||||||
FactoryGirl.attributes_for(:conversation_entity).merge!(
|
FactoryGirl.attributes_for(:conversation_entity).merge!(
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module DiasporaFederation
|
||||||
parent_guid: parent.guid,
|
parent_guid: parent.guid,
|
||||||
parent_type: parent.entity_type,
|
parent_type: parent.entity_type,
|
||||||
parent: parent_entity
|
parent: parent_entity
|
||||||
).send(:xml_elements).merge(parent: parent_entity)
|
).send(:enriched_properties).merge(parent: parent_entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:xml) { <<-XML }
|
let(:xml) { <<-XML }
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module DiasporaFederation
|
||||||
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
|
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
|
||||||
let(:data) {
|
let(:data) {
|
||||||
FactoryGirl.build(:message_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
FactoryGirl.build(:message_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
|
||||||
.send(:xml_elements).merge(parent: parent_entity)
|
.send(:enriched_properties).merge(parent: parent_entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:xml) { <<-XML }
|
let(:xml) { <<-XML }
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module DiasporaFederation
|
||||||
parent_guid: parent.guid,
|
parent_guid: parent.guid,
|
||||||
parent_type: parent.entity_type,
|
parent_type: parent.entity_type,
|
||||||
parent: parent_entity
|
parent: parent_entity
|
||||||
).send(:xml_elements).merge(parent: parent_entity)
|
).send(:enriched_properties).merge(parent: parent_entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:xml) { <<-XML }
|
let(:xml) { <<-XML }
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ module DiasporaFederation
|
||||||
author: alice.diaspora_id,
|
author: alice.diaspora_id,
|
||||||
parent_guid: parent.guid,
|
parent_guid: parent.guid,
|
||||||
parent: parent_entity
|
parent: parent_entity
|
||||||
).send(:xml_elements).merge(parent: parent_entity)
|
).send(:enriched_properties).merge(parent: parent_entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:xml) { <<-XML }
|
let(:xml) { <<-XML }
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ module DiasporaFederation
|
||||||
target_guid: target.guid,
|
target_guid: target.guid,
|
||||||
target_type: target.entity_type,
|
target_type: target.entity_type,
|
||||||
target: target_entity
|
target: target_entity
|
||||||
).send(:xml_elements).tap do |data|
|
).send(:enriched_properties).tap do |data|
|
||||||
data[:target_author_signature] = nil
|
data[:target_author_signature] = nil
|
||||||
data[:target] = target_entity
|
data[:target] = target_entity
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module DiasporaFederation
|
||||||
target_guid: target.guid,
|
target_guid: target.guid,
|
||||||
target_type: target.entity_type,
|
target_type: target.entity_type,
|
||||||
target: target_entity
|
target: target_entity
|
||||||
).send(:xml_elements).merge(target: target_entity)
|
).send(:enriched_properties).merge(target: target_entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:xml) { <<-XML }
|
let(:xml) { <<-XML }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue