Class: RelayableRetraction

Inherits:
SignedRetraction show all
Defined in:
lib/diaspora/federated/relayable_retraction.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Attribute Summary collapse

Attributes inherited from SignedRetraction

#sender, #target_author_signature, #target_guid, #target_type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SignedRetraction

#author, #guid, #sender_handle, #sender_handle=, #subscribers, #target, #target=, #target_author_signature_valid?

Methods included from Diaspora::Encryptable

#sign_with_key, #signable_string, #verify_signature

Methods included from Diaspora::Federated::Base

included

Instance Attribute Details

#parent_author_signatureObject

Returns the value of attribute parent_author_signature


8
9
10
# File 'lib/diaspora/federated/relayable_retraction.rb', line 8

def parent_author_signature
  @parent_author_signature
end

Class Method Details

.build(sender, target) ⇒ Object


18
19
20
21
22
# File 'lib/diaspora/federated/relayable_retraction.rb', line 18

def self.build(sender, target)
  retraction = super
  retraction.parent_author_signature = retraction.sign_with_key(sender.encryption_key) if defined?(target.parent) && sender.person == target.parent.author
  retraction
end

Instance Method Details

#diaspora_handleObject


24
25
26
# File 'lib/diaspora/federated/relayable_retraction.rb', line 24

def diaspora_handle
  self.sender_handle
end

#parent_author_signature_valid?Boolean


60
61
62
# File 'lib/diaspora/federated/relayable_retraction.rb', line 60

def parent_author_signature_valid?
  verify_signature(self.parent_author_signature, self.parent.author)
end

#perform(receiving_user) ⇒ Object


32
33
34
35
36
37
38
39
# File 'lib/diaspora/federated/relayable_retraction.rb', line 32

def perform receiving_user
  Rails.logger.debug "Performing relayable retraction for #{target_guid}"
  if not self.parent_author_signature.nil? or self.parent.author.remote?
    # Don't destroy a relayable unless the top-level owner has received it, otherwise it may not get relayed
    self.target.destroy
    Rails.logger.info("event=relayable_retraction status =complete target_type=#{self.target_type} guid =#{self.target_guid}")
  end
end

#receive(recipient, sender) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/diaspora/federated/relayable_retraction.rb', line 41

def receive(recipient, sender)
  if self.target.nil?
    Rails.logger.info("event=retraction status=abort reason='no post found' sender=#{sender.diaspora_handle} target_guid=#{target_guid}")
    return
  elsif self.parent.author == recipient.person && self.target_author_signature_valid?
    #this is a retraction from the downstream object creator, and the recipient is the upstream owner
    self.parent_author_signature = self.sign_with_key(recipient.encryption_key)
    Postzord::Dispatcher.build(recipient, self).post
    self.perform(recipient)
  elsif self.parent_author_signature_valid?
    #this is a retraction from the upstream owner
    self.perform(recipient)
  else
    Rails.logger.info("event=receive status=abort reason='object signature not valid' recipient=#{recipient.diaspora_handle} sender=#{self.parent.author.diaspora_handle} payload_type=#{self.class} parent_id=#{self.parent.id}")
    return
  end
  self
end

#relayable?Boolean


28
29
30
# File 'lib/diaspora/federated/relayable_retraction.rb', line 28

def relayable?
  true
end

#signable_accessorsObject


12
13
14
# File 'lib/diaspora/federated/relayable_retraction.rb', line 12

def signable_accessors
  super - ['parent_author_signature']
end