remove old SignedRetraction and RelayableRetraction

This commit is contained in:
Benjamin Neff 2016-06-11 04:29:02 +02:00
parent 9144a4aadd
commit 4d8211b641
6 changed files with 3 additions and 219 deletions

View file

@ -4,8 +4,7 @@
module Diaspora
module Federated
require 'diaspora/federated/retraction'
require 'diaspora/federated/signed_retraction'
require 'diaspora/federated/relayable_retraction'
require "diaspora/federated/base"
require "diaspora/federated/retraction"
end
end

View file

@ -1,45 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class RelayableRetraction < SignedRetraction
attr_accessor :parent_author_signature
delegate :parent, :parent_author, to: :target, allow_nil: true
def signable_accessors
super - ['parent_author_signature']
end
# @param sender [User]
# @param target [Object]
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
def diaspora_handle
self.sender_handle
end
def relayable?
true
end
def perform receiving_user
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
logger.info "event=relayable_retraction status=complete target_type=#{target_type} guid=#{target_guid}"
end
end
def parent_author_signature_valid?
verify_signature(self.parent_author_signature, self.parent.author)
end
def parent_diaspora_handle
target.author.diaspora_handle
end
end

View file

@ -1,78 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class SignedRetraction
include Diaspora::Federated::Base
include Diaspora::Encryptable
attr_accessor :target_guid,
:target_type,
:target_author_signature,
:sender
#NOTE(fix this hack -- go through the app and make sure we only call RelayableRetraction in a unified way)
def author
if sender.is_a?(User)
sender.person
else
sender
end
end
def sender_handle= new_sender_handle
@sender = Person.where(:diaspora_handle => new_sender_handle).first
end
def sender_handle
@sender.diaspora_handle
end
def diaspora_handle
self.sender_handle
end
def subscribers
target.subscribers
end
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
def target
@target ||= self.target_type.constantize.where(:guid => target_guid).first
end
def guid
target_guid
end
def target= new_target
@target = new_target
@target_type = new_target.class.to_s
@target_guid = new_target.guid
end
def perform receiving_user
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 && !target.destroyed?
self.target.destroy
end
logger.info "event=retraction status=complete target_type=#{target_type} guid=#{target_guid}"
end
def target_author_signature_valid?
verify_signature(self.target_author_signature, self.target.author)
end
end

View file

@ -1,43 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require Rails.root.join("spec", "shared_behaviors", "relayable")
describe RelayableRetraction do
before do
@local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = FactoryGirl.build(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "hi", :to => @local_luke.aspects.first
end
context "when retracting a comment" do
before do
skip # TODO
@comment= @local_luke.comment!(@local_parent, "yo")
@retraction= @local_luke.retract(@comment)
end
describe "#parent" do
it "delegates to to target" do
expect(@retraction.target).to receive(:parent)
@retraction.parent
end
end
describe "#parent_author" do
it "delegates to target" do
expect(@retraction.target).to receive(:parent_author)
@retraction.parent_author
end
end
describe "#subscribers" do
it "delegates it to target" do
expect(@retraction.target).to receive(:subscribers)
@retraction.subscribers
end
end
end
end

View file

@ -1,48 +0,0 @@
require 'spec_helper'
describe SignedRetraction do
before do
@post = FactoryGirl.create(:status_message, :author => bob.person, :public => true)
@resharer = FactoryGirl.create(:user)
@post.reshares << FactoryGirl.create(:reshare, :root => @post, :author => @resharer.person)
@post.save!
end
describe '#perform' do
it "dispatches the retraction onward to recipients of the recipient's reshare" do
retraction = described_class.build(bob, @post)
onward_retraction = retraction.dup
expect(retraction).to receive(:dup).and_return(onward_retraction)
dis = double
expect(Postzord::Dispatcher).to receive(:build).with(@resharer, onward_retraction).and_return(dis)
expect(dis).to receive(:post)
retraction.perform(@resharer)
end
it 'relays the retraction onward even if the post does not exist' do
skip # TODO
remote_post = FactoryGirl.create(:status_message, :public => true)
bob.post(:reshare, :root_guid => remote_post.guid)
alice.post(:reshare, :root_guid => remote_post.guid)
remote_retraction = described_class.new.tap{|r|
r.target_type = remote_post.type
r.target_guid = remote_post.guid
r.sender = remote_post.author
allow(r).to receive(:target_author_signature_valid?).and_return(true)
}
remote_retraction.dup.perform(bob)
expect(Post.exists?(:id => remote_post.id)).to be false
dis = double
expect(Postzord::Dispatcher).to receive(:build){ |sender, retraction|
expect(sender).to eq(alice)
expect(retraction.sender).to eq(alice.person)
dis
}
expect(dis).to receive(:post)
remote_retraction.perform(alice)
end
end
end

View file

@ -33,8 +33,7 @@ shared_examples_for "it is relayable" do
it "sends a retraction for the object" do
skip 'need to figure out how to test this'
expect(RelayableRetraction).to receive(:build)
expect(Postzord::Dispatcher).to receive(:build)
expect(Retraction).to receive(:for)
@relayable.valid?
end