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

Additional properties from parsed input object

Returns:

  • (Hash)

    additional elements



14
15
16
# File 'lib/diaspora_federation/entities/relayable.rb', line 14

def additional_data
  @additional_data
end

#authorString (readonly)

The diaspora* ID of the author

Returns:

  • (String)

    diaspora* ID

See Also:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/diaspora_federation/entities/relayable.rb', line 43

def self.included(klass)
  klass.class_eval do
    property :author, :string
    property :guid, :string
    property :parent_guid, :string
    property :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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/diaspora_federation/entities/relayable.rb', line 43

def self.included(klass)
  klass.class_eval do
    property :author, :string
    property :guid, :string
    property :parent_guid, :string
    property :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:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/diaspora_federation/entities/relayable.rb', line 43

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

  klass.extend Parsing
end

#parentRelatedEntity (readonly)

Meta information about the parent object

Returns:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/diaspora_federation/entities/relayable.rb', line 43

def self.included(klass)
  klass.class_eval do
    property :author, :string
    property :guid, :string
    property :parent_guid, :string
    property :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:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/diaspora_federation/entities/relayable.rb', line 43

def self.included(klass)
  klass.class_eval do
    property :author, :string
    property :guid, :string
    property :parent_guid, :string
    property :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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/diaspora_federation/entities/relayable.rb', line 43

def self.included(klass)
  klass.class_eval do
    property :author, :string
    property :guid, :string
    property :parent_guid, :string
    property :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:



61
62
63
64
65
66
# File 'lib/diaspora_federation/entities/relayable.rb', line 61

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

  super(data)
end

#sender_valid?(sender) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#signature_orderArray

The order for signing

Returns:

  • (Array)


97
98
99
100
101
# File 'lib/diaspora_federation/entities/relayable.rb', line 97

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])
end

#to_json(*_args) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/diaspora_federation/entities/relayable.rb', line 86

def to_json(*_args)
  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



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

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:



73
74
75
# File 'lib/diaspora_federation/entities/relayable.rb', line 73

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