Class: SignedRetraction

Inherits:
Object
  • Object
show all
Includes:
Diaspora::Encryptable, Diaspora::Federated::Base
Defined in:
lib/diaspora/federated/signed_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.

Direct Known Subclasses

RelayableRetraction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::Encryptable

#sign_with_key, #signable_string, #verify_signature

Methods included from Diaspora::Federated::Base

included

Instance Attribute Details

#senderObject

Returns the value of attribute sender


16
17
18
# File 'lib/diaspora/federated/signed_retraction.rb', line 16

def sender
  @sender
end

#target_author_signatureObject

Returns the value of attribute target_author_signature


16
17
18
# File 'lib/diaspora/federated/signed_retraction.rb', line 16

def target_author_signature
  @target_author_signature
end

#target_guidObject

Returns the value of attribute target_guid


16
17
18
# File 'lib/diaspora/federated/signed_retraction.rb', line 16

def target_guid
  @target_guid
end

#target_typeObject

Returns the value of attribute target_type


16
17
18
# File 'lib/diaspora/federated/signed_retraction.rb', line 16

def target_type
  @target_type
end

Class Method Details

.build(sender, target) ⇒ Object


53
54
55
56
57
58
59
# File 'lib/diaspora/federated/signed_retraction.rb', line 53

def self.build(sender, target)
  retraction = self.new
  retraction.sender = sender
  retraction.target = target
  retraction.target_author_signature = retraction.sign_with_key(sender.encryption_key) if sender.person == target.author
  retraction
end

Instance Method Details

#authorObject

NOTE(fix this hack – go through the app and make sure we only call RelayableRetraction in a unified way)


22
23
24
25
26
27
28
# File 'lib/diaspora/federated/signed_retraction.rb', line 22

def author
  if sender.is_a?(User)
    sender.person
  else
    sender
  end
end

#diaspora_handleObject


45
46
47
# File 'lib/diaspora/federated/signed_retraction.rb', line 45

def diaspora_handle
  self.sender_handle
end

#guidObject


65
66
67
# File 'lib/diaspora/federated/signed_retraction.rb', line 65

def guid
  target_guid
end

#perform(receiving_user) ⇒ Object


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/diaspora/federated/signed_retraction.rb', line 74

def perform receiving_user
  Rails.logger.debug "Performing retraction for #{target_guid}"
  if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_guid => target_guid).first
    onward_retraction = self.dup
    onward_retraction.sender = receiving_user.person
    Postzord::Dispatcher.build(receiving_user, onward_retraction).post
  end
  if target
    self.target.destroy
  end
  Rails.logger.info("event=retraction status =complete target_type=#{self.target_type} guid =#{self.target_guid}")
end

#receive(recipient, sender) ⇒ Object


87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/diaspora/federated/signed_retraction.rb', line 87

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.target_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.sender_handle} payload_type=#{self.class}")
    return
  end
  self
end

#sender_handleObject


41
42
43
# File 'lib/diaspora/federated/signed_retraction.rb', line 41

def sender_handle
  @sender.diaspora_handle
end

#sender_handle=(new_sender_handle) ⇒ Object


37
38
39
# File 'lib/diaspora/federated/signed_retraction.rb', line 37

def sender_handle= new_sender_handle
  @sender = Person.where(:diaspora_handle => new_sender_handle).first
end

#signable_accessorsObject


30
31
32
33
34
35
# File 'lib/diaspora/federated/signed_retraction.rb', line 30

def signable_accessors
    accessors = self.class.roxml_attrs.collect do |definition|
      definition.accessor
    end
    accessors - ['target_author_signature', 'sender_handle']
end

#subscribers(user) ⇒ Object


49
50
51
# File 'lib/diaspora/federated/signed_retraction.rb', line 49

def subscribers(user)
  self.target.subscribers(user)
end

#targetObject


61
62
63
# File 'lib/diaspora/federated/signed_retraction.rb', line 61

def target
  @target ||= self.target_type.constantize.where(:guid => target_guid).first
end

#target=(new_target) ⇒ Object


68
69
70
71
72
# File 'lib/diaspora/federated/signed_retraction.rb', line 68

def target= new_target
  @target = new_target
  @target_type = new_target.class.to_s
  @target_guid = new_target.guid
end

#target_author_signature_valid?Boolean


101
102
103
# File 'lib/diaspora/federated/signed_retraction.rb', line 101

def target_author_signature_valid?
  verify_signature(self.target_author_signature, self.target.author)
end