Module: DiasporaFederation::Entities::Relayable

Includes:
Signable
Included in:
Comment, EventParticipation, Like, PollParticipation
Defined in:
lib/diaspora_federation/entities/relayable.rb

Overview

This is a module that defines common properties for relayable entities which include Like, Comment, Participation, Message, etc. Each relayable has a parent, identified by guid. Relayables are also signed and signing/verification logic is embedded into Salmon XML processing code.

Defined Under Namespace

Modules: Parsing Classes: AuthorPrivateKeyNotFound

Constant Summary

Constants included from Signable

Signable::DIGEST

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Signable

#sign_with_key

Instance Attribute Details

#additional_dataHash (readonly)

Additional properties from parsed input object

Returns:

  • (Hash)

    additional elements



12
13
14
# File 'lib/diaspora_federation/entities/relayable.rb', line 12

def additional_data
  @additional_data
end

#authorString (readonly)

The diaspora* ID of the author

Returns:

  • (String)

    diaspora* ID

See Also:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diaspora_federation/entities/relayable.rb', line 47

def self.included(klass)
  klass.class_eval do
    property :author, :string, xml_name: :diaspora_handle
    property :guid, :string
    property :parent_guid, :string
    property :author_signature, :string, default: nil
    property :parent_author_signature, :string, default: nil
    entity :parent, Entities::RelatedEntity
  end

  klass.extend Parsing
end

#author_signatureString (readonly)

Contains a signature of the entity using the private key of the author of a relayable itself. The presence of this signature is mandatory. Without it the entity won't be accepted by a target pod.

Returns:

  • (String)

    author signature



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diaspora_federation/entities/relayable.rb', line 47

def self.included(klass)
  klass.class_eval do
    property :author, :string, xml_name: :diaspora_handle
    property :guid, :string
    property :parent_guid, :string
    property :author_signature, :string, default: nil
    property :parent_author_signature, :string, default: nil
    entity :parent, Entities::RelatedEntity
  end

  klass.extend Parsing
end

#guidString (readonly)

A random string of at least 16 chars

Returns:

  • (String)

    comment guid

See Also:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diaspora_federation/entities/relayable.rb', line 47

def self.included(klass)
  klass.class_eval do
    property :author, :string, xml_name: :diaspora_handle
    property :guid, :string
    property :parent_guid, :string
    property :author_signature, :string, default: nil
    property :parent_author_signature, :string, default: nil
    entity :parent, Entities::RelatedEntity
  end

  klass.extend Parsing
end

#parentRelatedEntity (readonly)

Meta information about the parent object

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diaspora_federation/entities/relayable.rb', line 47

def self.included(klass)
  klass.class_eval do
    property :author, :string, xml_name: :diaspora_handle
    property :guid, :string
    property :parent_guid, :string
    property :author_signature, :string, default: nil
    property :parent_author_signature, :string, default: nil
    entity :parent, Entities::RelatedEntity
  end

  klass.extend Parsing
end

#parent_author_signatureString (readonly)

Deprecated.

This signature isn't required anymore, because we can check the signature from the parent author in the MagicEnvelope.

Contains a signature of the entity using the private key of the author of a parent post.

Returns:

  • (String)

    parent author signature



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diaspora_federation/entities/relayable.rb', line 47

def self.included(klass)
  klass.class_eval do
    property :author, :string, xml_name: :diaspora_handle
    property :guid, :string
    property :parent_guid, :string
    property :author_signature, :string, default: nil
    property :parent_author_signature, :string, default: nil
    entity :parent, Entities::RelatedEntity
  end

  klass.extend Parsing
end

#parent_guidString (readonly)

Returns parent guid

Returns:

  • (String)

    parent guid

See Also:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diaspora_federation/entities/relayable.rb', line 47

def self.included(klass)
  klass.class_eval do
    property :author, :string, xml_name: :diaspora_handle
    property :guid, :string
    property :parent_guid, :string
    property :author_signature, :string, default: nil
    property :parent_author_signature, :string, default: nil
    entity :parent, Entities::RelatedEntity
  end

  klass.extend Parsing
end

Class Method Details

.included(klass) ⇒ Object

On inclusion of this module the required properties for a relayable are added to the object that includes it.

Parameters:

  • klass (Entity)

    the entity in which it is included



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diaspora_federation/entities/relayable.rb', line 47

def self.included(klass)
  klass.class_eval do
    property :author, :string, xml_name: :diaspora_handle
    property :guid, :string
    property :parent_guid, :string
    property :author_signature, :string, default: nil
    property :parent_author_signature, :string, default: nil
    entity :parent, Entities::RelatedEntity
  end

  klass.extend Parsing
end

Instance Method Details

#initialize(data, signature_order = nil, additional_data = {}) ⇒ Object

Initializes a new relayable Entity with order and additional xml elements

Parameters:

  • data (Hash)

    entity data

  • signature_order (Array) (defaults to: nil)

    order for the signature

  • additional_data (Hash) (defaults to: {})

    additional xml elements

See Also:



66
67
68
69
70
71
# File 'lib/diaspora_federation/entities/relayable.rb', line 66

def initialize(data, signature_order=nil, additional_data={})
  self.signature_order = signature_order if signature_order
  @additional_data = additional_data

  super(data)
end

#sender_valid?(sender) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/diaspora_federation/entities/relayable.rb', line 82

def sender_valid?(sender)
  (sender == author && parent.root.local) || sender == parent.root.author
end

#signature_orderArray

The order for signing

Returns:

  • (Array)


102
103
104
105
106
# File 'lib/diaspora_federation/entities/relayable.rb', line 102

def signature_order
  @signature_order || self.class.class_props.keys.reject {|key|
    self.class.optional_props.include?(key) && public_send(key).nil?
  } - %i[author_signature parent_author_signature parent]
end

#to_jsonObject



91
92
93
94
95
96
97
98
# File 'lib/diaspora_federation/entities/relayable.rb', line 91

def to_json
  super.merge!(property_order: signature_order).tap {|json_hash|
    missing_properties = json_hash[:property_order] - json_hash[:entity_data].keys
    missing_properties.each {|property|
      json_hash[:entity_data][property] = nil
    }
  }
end

#to_sString

Returns string representation of this object

Returns:

  • (String)

    string representation of this object



87
88
89
# File 'lib/diaspora_federation/entities/relayable.rb', line 87

def to_s
  "#{super}#{":#{parent_type}" if respond_to?(:parent_type)}:#{parent_guid}"
end

#verify_signatureObject

Verifies the author_signature if needed.

Raises:

See Also:



78
79
80
# File 'lib/diaspora_federation/entities/relayable.rb', line 78

def verify_signature
  super(author, :author_signature) unless author == parent.root.author
end