WIP refactor namespacing for federation libs, into Diaspora::Federated

This commit is contained in:
Oliver Azevedo Barnes 2013-08-07 17:29:07 -05:00
parent 5564644306
commit 1c9d65e94c
29 changed files with 411 additions and 431 deletions

View file

@ -61,7 +61,7 @@ class Contact < ActiveRecord::Base
end
def generate_request
Request.diaspora_initialize(:from => self.user.person,
Diaspora::Federated::Request.diaspora_initialize(:from => self.user.person,
:to => self.person,
:into => aspects.first)
end

View file

@ -83,7 +83,7 @@ private
n = notification_type.new(:target => target,
:recipient_id => recipient.id)
n.actors = n.actors | [actor]
n.unread = false if target.is_a? Request
n.unread = false if target.is_a? Diaspora::Federated::Request
n.save!
n
end

View file

@ -297,11 +297,11 @@ class User < ActiveRecord::Base
######### Posts and Such ###############
def retract(target, opts={})
if target.respond_to?(:relayable?) && target.relayable?
retraction = RelayableRetraction.build(self, target)
retraction = Diaspora::Federated::RelayableRetraction.build(self, target)
elsif target.is_a? Post
retraction = SignedRetraction.build(self, target)
retraction = Diaspora::Federated::SignedRetraction.build(self, target)
else
retraction = Retraction.for(target)
retraction = Diaspora::Federated::Retraction.for(target)
end
if target.is_a?(Post)

View file

@ -56,7 +56,7 @@ module User::Connecting
def disconnect(bad_contact, opts={})
person = bad_contact.person
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}")
retraction = Retraction.for(self)
retraction = Diaspora::Federated::Retraction.for(self)
retraction.subscribers = [person]#HAX
Postzord::Dispatcher.build(self, retraction).post

View file

@ -316,8 +316,8 @@ ActiveRecord::Schema.define(:version => 20130801063213) do
t.boolean "favorite", :default => false
t.string "facebook_id"
t.string "tweet_id"
t.text "tumblr_ids"
t.integer "open_graph_cache_id"
t.text "tumblr_ids"
end
add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true
@ -481,30 +481,6 @@ ActiveRecord::Schema.define(:version => 20130801063213) do
add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token"
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
add_foreign_key "aspect_memberships", "aspects", :name => "aspect_memberships_aspect_id_fk", :dependent => :delete
add_foreign_key "aspect_memberships", "contacts", :name => "aspect_memberships_contact_id_fk", :dependent => :delete
add_foreign_key "aspect_visibilities", "aspects", :name => "aspect_visibilities_aspect_id_fk", :dependent => :delete
add_foreign_key "comments", "people", :name => "comments_author_id_fk", :column => "author_id", :dependent => :delete
add_foreign_key "contacts", "people", :name => "contacts_person_id_fk", :dependent => :delete
add_foreign_key "conversation_visibilities", "conversations", :name => "conversation_visibilities_conversation_id_fk", :dependent => :delete
add_foreign_key "conversation_visibilities", "people", :name => "conversation_visibilities_person_id_fk", :dependent => :delete
add_foreign_key "conversations", "people", :name => "conversations_author_id_fk", :column => "author_id", :dependent => :delete
add_foreign_key "invitations", "users", :name => "invitations_recipient_id_fk", :column => "recipient_id", :dependent => :delete
add_foreign_key "invitations", "users", :name => "invitations_sender_id_fk", :column => "sender_id", :dependent => :delete
add_foreign_key "likes", "people", :name => "likes_author_id_fk", :column => "author_id", :dependent => :delete
add_foreign_key "messages", "conversations", :name => "messages_conversation_id_fk", :dependent => :delete
add_foreign_key "messages", "people", :name => "messages_author_id_fk", :column => "author_id", :dependent => :delete
add_foreign_key "notification_actors", "notifications", :name => "notification_actors_notification_id_fk", :dependent => :delete
add_foreign_key "posts", "people", :name => "posts_author_id_fk", :column => "author_id", :dependent => :delete
add_foreign_key "profiles", "people", :name => "profiles_person_id_fk", :dependent => :delete

View file

@ -22,7 +22,7 @@ module NavigationHelpers
when /^my acceptance form page$/
invite_code_path(InvitationCode.first)
when /^the requestors profile$/
person_path(Request.where(:recipient_id => @me.person.id).first.sender)
person_path(Diaspora::Federated::Request.where(:recipient_id => @me.person.id).first.sender)
when /^"([^\"]*)"'s page$/
person_path(User.find_by_email($1).person)
when /^my account settings page$/

View file

@ -9,4 +9,5 @@ module Diaspora
require 'diaspora/markdownify'
require 'diaspora/mentionable'
require 'diaspora/exporter'
require 'diaspora/federated'
end

12
lib/diaspora/federated.rb Normal file
View file

@ -0,0 +1,12 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Diaspora
module Federated
require 'diaspora/federated/request'
require 'diaspora/federated/retraction'
require 'diaspora/federated/signed_retraction'
require 'diaspora/federated/relayable_retraction'
end
end

View file

@ -1,69 +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.
module Diaspora
module Federated
module Messages
class RelayableRetraction < SignedRetraction
xml_name :relayable_retraction
xml_attr :parent_author_signature
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
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
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
def parent_author_signature_valid?
verify_signature(self.parent_author_signature, self.parent.author)
end
end
end
end
end

View file

@ -1,107 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# t
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Diaspora
module Federated
module Messages
class Request
include Diaspora::Federated::Base
include ActiveModel::Validations
attr_accessor :sender, :recipient, :aspect
xml_accessor :sender_handle
xml_accessor :recipient_handle
validates :sender, :presence => true
validates :recipient, :presence => true
validate :not_already_connected
validate :not_friending_yourself
# Initalize variables
# @note we should be using ActiveModel::Serialization for this
# @return [Request]
def self.diaspora_initialize(opts = {})
req = self.new
req.sender = opts[:from]
req.recipient = opts[:to]
req.aspect = opts[:into]
req
end
# Alias of sender_handle
# @return [String]
def diaspora_handle
sender_handle
end
# @note Used for XML marshalling
# @return [String]
def sender_handle
sender.diaspora_handle
end
def sender_handle= sender_handle
self.sender = Person.where(:diaspora_handle => sender_handle).first
end
# @note Used for XML marshalling
# @return [String]
def recipient_handle
recipient.diaspora_handle
end
def recipient_handle= recipient_handle
self.recipient = Person.where(:diaspora_handle => recipient_handle).first
end
# Defines the abstract interface used in sending a corresponding [Notification] given the [Request]
# @param user [User]
# @param person [Person]
# @return [Notifications::StartedSharing]
def notification_type(user, person)
Notifications::StartedSharing
end
# Defines the abstract interface used in sending the [Request]
# @param user [User]
# @return [Array<Person>] The recipient of the request
def subscribers(user)
[self.recipient]
end
# Finds or initializes a corresponding [Contact], and will set Contact#sharing to true
# Follows back if user setting is set so
# @note A [Contact] may already exist if the [Request]'s recipient is sharing with the sender
# @return [Request]
def receive(user, person)
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
contact = user.contacts.find_or_initialize_by_person_id(self.sender.id)
contact.sharing = true
contact.save
user.share_with(person, user.auto_follow_back_aspect) if user.auto_follow_back && !contact.receiving
self
end
private
# Checks if a [Contact] does not already exist between the requesting [User] and receiving [Person]
def not_already_connected
if sender && recipient && Contact.where(:user_id => self.recipient.owner_id, :person_id => self.sender.id).exists?
errors[:base] << 'You have already connected to this person'
end
end
# Checks to see that the requesting [User] is not sending a request to himself
def not_friending_yourself
if self.recipient == self.sender
errors[:base] << 'You can not friend yourself'
end
end
end
end
end
end

View file

@ -1,69 +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.
module Diaspora
module Federated
module Messages
class Retraction
include Diaspora::Federated::Base
xml_accessor :post_guid
xml_accessor :diaspora_handle
xml_accessor :type
attr_accessor :person, :object, :subscribers
def subscribers(user)
unless self.type == 'Person'
@subscribers ||= self.object.subscribers(user)
@subscribers -= self.object.resharers unless self.object.is_a?(Photo)
@subscribers
else
raise 'HAX: you must set the subscribers manaully before unfriending' if @subscribers.nil?
@subscribers
end
end
def self.for(object)
retraction = self.new
if object.is_a? User
retraction.post_guid = object.person.guid
retraction.type = object.person.class.to_s
else
retraction.post_guid = object.guid
retraction.type = object.class.to_s
retraction.object = object
end
retraction.diaspora_handle = object.diaspora_handle
retraction
end
def target
@target ||= self.type.constantize.where(:guid => post_guid).first
end
def perform receiving_user
Rails.logger.debug "Performing retraction for #{post_guid}"
self.target.destroy if self.target
Rails.logger.info("event=retraction status=complete type=#{self.type} guid=#{self.post_guid}")
end
def receive(user, person)
if self.type == 'Person'
unless self.person.guid.to_s == self.post_guid.to_s
Rails.logger.info("event=receive status=abort reason='sender is not the person he is trying to retract' recipient=#{self.diaspora_handle} sender=#{self.person.diaspora_handle} payload_type=#{self.class} retraction_type=person")
return
end
user.disconnected_by(self.target)
elsif self.target.nil? || self.target.author != self.person
Rails.logger.info("event=retraction status=abort reason='no post found authored by retractor' sender=#{person.diaspora_handle} post_guid=#{post_guid}")
else
self.perform(user)
end
self
end
end
end
end
end

View file

@ -1,110 +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.
module Diaspora
module Federated
module Messages
class SignedRetraction
include Diaspora::Federated::Base
include Diaspora::Encryptable
xml_name :signed_retraction
xml_attr :target_guid
xml_attr :target_type
xml_attr :sender_handle
xml_attr :target_author_signature
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 signable_accessors
accessors = self.class.roxml_attrs.collect do |definition|
definition.accessor
end
accessors - ['target_author_signature', 'sender_handle']
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(user)
self.target.subscribers(user)
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
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
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
def target_author_signature_valid?
verify_signature(self.target_author_signature, self.target.author)
end
end
end
end
end

View file

@ -0,0 +1,67 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Diaspora
module Federated
class RelayableRetraction < SignedRetraction
xml_name :relayable_retraction
xml_attr :parent_author_signature
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
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
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
def parent_author_signature_valid?
verify_signature(self.parent_author_signature, self.parent.author)
end
end
end
end

View file

@ -0,0 +1,105 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# t
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Diaspora
module Federated
class Request
include Base
include ActiveModel::Validations
attr_accessor :sender, :recipient, :aspect
xml_accessor :sender_handle
xml_accessor :recipient_handle
validates :sender, :presence => true
validates :recipient, :presence => true
validate :not_already_connected
validate :not_friending_yourself
# Initalize variables
# @note we should be using ActiveModel::Serialization for this
# @return [Request]
def self.diaspora_initialize(opts = {})
req = self.new
req.sender = opts[:from]
req.recipient = opts[:to]
req.aspect = opts[:into]
req
end
# Alias of sender_handle
# @return [String]
def diaspora_handle
sender_handle
end
# @note Used for XML marshalling
# @return [String]
def sender_handle
sender.diaspora_handle
end
def sender_handle= sender_handle
self.sender = Person.where(:diaspora_handle => sender_handle).first
end
# @note Used for XML marshalling
# @return [String]
def recipient_handle
recipient.diaspora_handle
end
def recipient_handle= recipient_handle
self.recipient = Person.where(:diaspora_handle => recipient_handle).first
end
# Defines the abstract interface used in sending a corresponding [Notification] given the [Request]
# @param user [User]
# @param person [Person]
# @return [Notifications::StartedSharing]
def notification_type(user, person)
Notifications::StartedSharing
end
# Defines the abstract interface used in sending the [Request]
# @param user [User]
# @return [Array<Person>] The recipient of the request
def subscribers(user)
[self.recipient]
end
# Finds or initializes a corresponding [Contact], and will set Contact#sharing to true
# Follows back if user setting is set so
# @note A [Contact] may already exist if the [Request]'s recipient is sharing with the sender
# @return [Request]
def receive(user, person)
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
contact = user.contacts.find_or_initialize_by_person_id(self.sender.id)
contact.sharing = true
contact.save
user.share_with(person, user.auto_follow_back_aspect) if user.auto_follow_back && !contact.receiving
self
end
private
# Checks if a [Contact] does not already exist between the requesting [User] and receiving [Person]
def not_already_connected
if sender && recipient && Contact.where(:user_id => self.recipient.owner_id, :person_id => self.sender.id).exists?
errors[:base] << 'You have already connected to this person'
end
end
# Checks to see that the requesting [User] is not sending a request to himself
def not_friending_yourself
if self.recipient == self.sender
errors[:base] << 'You can not friend yourself'
end
end
end
end
end

View file

@ -0,0 +1,67 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Diaspora
module Federated
class Retraction
include Base
xml_accessor :post_guid
xml_accessor :diaspora_handle
xml_accessor :type
attr_accessor :person, :object, :subscribers
def subscribers(user)
unless self.type == 'Person'
@subscribers ||= self.object.subscribers(user)
@subscribers -= self.object.resharers unless self.object.is_a?(Photo)
@subscribers
else
raise 'HAX: you must set the subscribers manaully before unfriending' if @subscribers.nil?
@subscribers
end
end
def self.for(object)
retraction = self.new
if object.is_a? User
retraction.post_guid = object.person.guid
retraction.type = object.person.class.to_s
else
retraction.post_guid = object.guid
retraction.type = object.class.to_s
retraction.object = object
end
retraction.diaspora_handle = object.diaspora_handle
retraction
end
def target
@target ||= self.type.constantize.where(:guid => post_guid).first
end
def perform receiving_user
Rails.logger.debug "Performing retraction for #{post_guid}"
self.target.destroy if self.target
Rails.logger.info("event=retraction status=complete type=#{self.type} guid=#{self.post_guid}")
end
def receive(user, person)
if self.type == 'Person'
unless self.person.guid.to_s == self.post_guid.to_s
Rails.logger.info("event=receive status=abort reason='sender is not the person he is trying to retract' recipient=#{self.diaspora_handle} sender=#{self.person.diaspora_handle} payload_type=#{self.class} retraction_type=person")
return
end
user.disconnected_by(self.target)
elsif self.target.nil? || self.target.author != self.person
Rails.logger.info("event=retraction status=abort reason='no post found authored by retractor' sender=#{person.diaspora_handle} post_guid=#{post_guid}")
else
self.perform(user)
end
self
end
end
end
end

View file

@ -0,0 +1,108 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Diaspora
module Federated
class SignedRetraction
include Base
include Diaspora::Encryptable
xml_name :signed_retraction
xml_attr :target_guid
xml_attr :target_type
xml_attr :sender_handle
xml_attr :target_author_signature
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 signable_accessors
accessors = self.class.roxml_attrs.collect do |definition|
definition.accessor
end
accessors - ['target_author_signature', 'sender_handle']
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(user)
self.target.subscribers(user)
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
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
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
def target_author_signature_valid?
verify_signature(self.target_author_signature, self.target.author)
end
end
end
end

View file

@ -149,7 +149,7 @@ class Postzord::Dispatcher
if @object.instance_of?(StatusMessage)
Workers::PostToService.perform_async(service.id, @object.id, url)
end
if @object.instance_of?(SignedRetraction)
if @object.instance_of?(Diaspora::Federated::SignedRetraction)
Workers::DeletePostFromService.perform_async(service.id, @object.target.id)
end
end

View file

@ -99,7 +99,7 @@ class Postzord::Receiver::Private < Postzord::Receiver
end
def contact_required_unless_request
unless @object.is_a?(Request) || @user.contact_for(@sender)
unless @object.is_a?(Diaspora::Federated::Request) || @user.contact_for(@sender)
FEDERATION_LOGGER.error("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
return true
end
@ -107,7 +107,7 @@ class Postzord::Receiver::Private < Postzord::Receiver
def assign_sender_handle_if_request
#special casey
if @object.is_a?(Request)
if @object.is_a?(Diaspora::Federated::Request)
@object.sender_handle = @sender.diaspora_handle
end
end

View file

@ -30,7 +30,7 @@ class Postzord::Receiver::Public < Postzord::Receiver
receive_relayable
elsif @object.is_a?(AccountDeletion)
#nothing
elsif @object.is_a?(SignedRetraction) # feels like a hack
elsif @object.is_a?(Diaspora::Federated::SignedRetraction) # feels like a hack
self.recipient_user_ids.each do |user_id|
user = User.where(id: user_id).first
@object.perform user if user

View file

@ -47,7 +47,7 @@ def expect_error(partial_message, &block)# DOES NOT REQUIRE ERROR!!
end
def bogus_retraction(&block)
ret = Retraction.new
ret = Diaspora::Federated::Retraction.new
yield ret
ret
end

View file

@ -317,7 +317,7 @@ describe 'a user receives a post' do
let(:zord) { Postzord::Receiver::Private.new(alice, person: bob.person) }
it 'should accept retractions' do
retraction = Retraction.for(message)
retraction = Diaspora::Federated::Retraction.for(message)
xml = retraction.to_diaspora_xml
expect {
@ -327,7 +327,7 @@ describe 'a user receives a post' do
it 'should accept relayable retractions' do
comment = bob.comment! message, "and dogs"
retraction = RelayableRetraction.build(bob, comment)
retraction = Diaspora::Federated::RelayableRetraction.build(bob, comment)
xml = retraction.to_diaspora_xml
expect {
@ -337,7 +337,7 @@ describe 'a user receives a post' do
it 'should accept signed retractions for public posts' do
message = bob.post(:status_message, text: "cats", public: true)
retraction = SignedRetraction.build(bob, message)
retraction = Diaspora::Federated::SignedRetraction.build(bob, message)
salmon = Postzord::Dispatcher::Public.salmon bob, retraction.to_diaspora_xml
xml = salmon.xml_for alice.person
zord = Postzord::Receiver::Public.new xml

View file

@ -4,9 +4,9 @@
require 'spec_helper'
require Rails.root.join("spec", "shared_behaviors", "relayable")
require Rails.root.join('lib', 'diaspora', 'federated', 'messages')
# require Rails.root.join('lib', 'diaspora', 'federated', 'messages')
describe Diaspora::Federated::Messages::RelayableRetraction do
describe Diaspora::Federated::RelayableRetraction do
before do
@local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = FactoryGirl.build(:status_message, :author => @remote_raphael)
@ -83,7 +83,7 @@ describe Diaspora::Federated::Messages::RelayableRetraction do
context 'from the upstream owner' do
before do
@comment = @local_luke.comment!(@remote_parent, "Yeah, it was great")
@retraction = RelayableRetraction.allocate
@retraction = described_class.allocate
@retraction.sender = @remote_raphael
@retraction.target = @comment
@retraction.stub!(:parent_author_signature_valid?).and_return(true)
@ -105,7 +105,7 @@ describe Diaspora::Federated::Messages::RelayableRetraction do
describe 'xml' do
before do
@comment = @local_leia.comment!(@local_parent, "yo")
@retraction = RelayableRetraction.build(@local_leia, @comment)
@retraction = described_class.build(@local_leia, @comment)
@retraction.parent_author_signature = 'PARENTSIGNATURE'
@retraction.target_author_signature = 'TARGETSIGNATURE'
@xml = @retraction.to_xml.to_s
@ -132,7 +132,7 @@ describe Diaspora::Federated::Messages::RelayableRetraction do
describe '.from_xml' do
before do
@marshalled = RelayableRetraction.from_xml(@xml)
@marshalled = described_class.from_xml(@xml)
end
it 'marshals the target' do

View file

@ -3,16 +3,15 @@
# the COPYRIGHT file.
require 'spec_helper'
require Rails.root.join('lib', 'diaspora', 'federated', 'messages')
describe Diaspora::Federated::Messages::Request do
describe Diaspora::Federated::Request do
before do
@aspect = alice.aspects.first
end
describe 'validations' do
before do
@request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
@request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
end
it 'is valid' do
@ -43,7 +42,7 @@ describe Diaspora::Federated::Messages::Request do
end
it 'is not to yourself' do
@request = Request.diaspora_initialize(:from => alice.person, :to => alice.person, :into => @aspect)
@request = described_class.diaspora_initialize(:from => alice.person, :to => alice.person, :into => @aspect)
@request.should_not be_valid
end
end
@ -52,7 +51,7 @@ describe Diaspora::Federated::Messages::Request do
it 'returns request_accepted' do
person = FactoryGirl.build:person
request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
alice.contacts.create(:person_id => person.id)
request.notification_type(alice, person).should == Notifications::StartedSharing
@ -61,14 +60,14 @@ describe Diaspora::Federated::Messages::Request do
describe '#subscribers' do
it 'returns an array with to field on a request' do
request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
request.subscribers(alice).should =~ [eve.person]
end
end
describe '#receive' do
it 'creates a contact' do
request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
lambda{
request.receive(eve, alice.person)
}.should change{
@ -80,7 +79,7 @@ describe Diaspora::Federated::Messages::Request do
alice.share_with(eve.person, alice.aspects.first)
lambda {
Request.diaspora_initialize(:from => eve.person, :to => alice.person,
described_class.diaspora_initialize(:from => eve.person, :to => alice.person,
:into => eve.aspects.first).receive(alice, eve.person)
}.should change {
alice.contacts.find_by_person_id(eve.person.id).mutual?
@ -89,7 +88,7 @@ describe Diaspora::Federated::Messages::Request do
end
it 'sets sharing' do
Request.diaspora_initialize(:from => eve.person, :to => alice.person,
described_class.diaspora_initialize(:from => eve.person, :to => alice.person,
:into => eve.aspects.first).receive(alice, eve.person)
alice.contact_for(eve.person).should be_sharing
end
@ -99,10 +98,10 @@ describe Diaspora::Federated::Messages::Request do
alice.auto_follow_back_aspect = alice.aspects.first
alice.save
Request.diaspora_initialize(:from => eve.person, :to => alice.person,
:into => eve.aspects.first).receive(alice, eve.person)
described_class.diaspora_initialize(:from => eve.person, :to => alice.person,
:into => eve.aspects.first).receive(alice, eve.person)
eve.contact_for(alice.person).should be_sharing
eve.contact_for( alice.person ).should be_sharing
end
it 'shares not back if auto_following is not enabled' do
@ -110,7 +109,7 @@ describe Diaspora::Federated::Messages::Request do
alice.auto_follow_back_aspect = alice.aspects.first
alice.save
Request.diaspora_initialize(:from => eve.person, :to => alice.person,
described_class.diaspora_initialize(:from => eve.person, :to => alice.person,
:into => eve.aspects.first).receive(alice, eve.person)
eve.contact_for(alice.person).should be_nil
@ -127,14 +126,14 @@ describe Diaspora::Federated::Messages::Request do
alice.should_not_receive(:share_with)
Request.diaspora_initialize(:from => eve.person, :to => alice.person,
described_class.diaspora_initialize(:from => eve.person, :to => alice.person,
:into => eve.aspects.first).receive(alice, eve.person)
end
end
context 'xml' do
before do
@request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
@request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
@xml = @request.to_xml.to_s
end
@ -149,7 +148,7 @@ describe Diaspora::Federated::Messages::Request do
context 'marshalling' do
it 'produces a request object' do
marshalled = Request.from_xml @xml
marshalled = described_class.from_xml @xml
marshalled.sender.should == alice.person
marshalled.recipient.should == eve.person

View file

@ -3,9 +3,9 @@
# the COPYRIGHT file.
require 'spec_helper'
require Rails.root.join('lib', 'diaspora', 'federated', 'messages')
# require Rails.root.join('lib', 'diaspora', 'federated', 'messages')
describe Diaspora::Federated::Messages::Retraction do
describe Diaspora::Federated::Retraction do
before do
@aspect = alice.aspects.first
alice.contacts.create(:person => eve.person, :aspects => [@aspect])
@ -14,7 +14,7 @@ describe Diaspora::Federated::Messages::Retraction do
describe 'serialization' do
it 'should have a post id after serialization' do
retraction = Retraction.for(@post)
retraction = described_class.for(@post)
xml = retraction.to_xml.to_s
xml.include?(@post.guid.to_s).should == true
end
@ -23,7 +23,7 @@ describe Diaspora::Federated::Messages::Retraction do
describe '#subscribers' do
context 'posts' do
before do
@retraction = Retraction.for(@post)
@retraction = described_class.for(@post)
@obj = @retraction.instance_variable_get(:@object)
@wanted_subscribers = @obj.subscribers(alice)
end
@ -43,7 +43,7 @@ describe Diaspora::Federated::Messages::Retraction do
context 'setting subscribers' do
it 'barfs if the type is a person, and subscribers instance varabile is not set' do
retraction = Retraction.for(alice)
retraction = described_class.for(alice)
obj = retraction.instance_variable_get(:@object)
lambda {
@ -52,7 +52,7 @@ describe Diaspora::Federated::Messages::Retraction do
end
it 'returns manually set subscribers' do
retraction = Retraction.for(alice)
retraction = described_class.for(alice)
retraction.subscribers = "fooey"
retraction.subscribers(alice).should == 'fooey'
end

View file

@ -1,7 +1,7 @@
require 'spec_helper'
require Rails.root.join('lib', 'diaspora', 'federated', 'messages')
# require Rails.root.join('lib', 'diaspora', 'federated', 'messages')
describe Diaspora::Federated::Messages::SignedRetraction do
describe Diaspora::Federated::SignedRetraction do
before do
@post = FactoryGirl.create(:status_message, :author => bob.person, :public => true)
@resharer = FactoryGirl.create(:user)
@ -10,7 +10,7 @@ describe Diaspora::Federated::Messages::SignedRetraction do
end
describe '#perform' do
it "dispatches the retraction onward to recipients of the recipient's reshare" do
retraction = SignedRetraction.build(bob, @post)
retraction = described_class.build(bob, @post)
onward_retraction = retraction.dup
retraction.should_receive(:dup).and_return(onward_retraction)
@ -25,7 +25,7 @@ describe Diaspora::Federated::Messages::SignedRetraction do
bob.post(:reshare, :root_guid => remote_post.guid)
alice.post(:reshare, :root_guid => remote_post.guid)
remote_retraction = SignedRetraction.new.tap{|r|
remote_retraction = described_class.new.tap{|r|
r.target_type = remote_post.type
r.target_guid = remote_post.guid
r.sender = remote_post.author

View file

@ -262,7 +262,7 @@ describe Postzord::Dispatcher do
end
it 'returns false for a relayable_retraction' do
f = RelayableRetraction.new
f = Diaspora::Federated::RelayableRetraction.new
f.target = FactoryGirl.create(:status_message, :public => true)
Postzord::Dispatcher.object_should_be_processed_as_public?(f).should be_false
end
@ -312,7 +312,7 @@ describe Postzord::Dispatcher do
end
it 'queues a job to delete if given retraction' do
retraction = SignedRetraction.build(alice, FactoryGirl.create(:status_message))
retraction = Diaspora::Federated::SignedRetraction.build(alice, FactoryGirl.create(:status_message))
mailman = Postzord::Dispatcher.build(alice, retraction, :url => "http://joindiaspora.com/p/123", :services => [@service])
Workers::DeletePostFromService.should_receive(:perform_async).with(anything, anything)

View file

@ -65,7 +65,7 @@ describe Notification do
describe '.notify' do
context 'with a request' do
before do
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
@request = Diaspora::Federated::Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
end
it 'calls Notification.create if the object has a notification_type' do

View file

@ -800,7 +800,7 @@ describe User do
context "posts" do
before do
SignedRetraction.stub(:build).and_return(@retraction)
Diaspora::Federated::SignedRetraction.stub(:build).and_return(@retraction)
@retraction.stub(:perform)
end

View file

@ -34,7 +34,7 @@ describe Diaspora::Relayable do
it "sends a retraction for the object" do
pending 'need to figure out how to test this'
RelayableRetraction.should_receive(:build)
Diaspora::Federated::RelayableRetraction.should_receive(:build)
Postzord::Dispatcher.should_receive(:build)
@relayable.valid?
end