Skip to content
Extraits de code Groupes Projets
Valider 119cb37b rédigé par Maxwell Salzberg's avatar Maxwell Salzberg
Parcourir les fichiers

DG MS; broke validations into methods in receiver

parent df87b398
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -34,12 +34,14 @@ module Postzord ...@@ -34,12 +34,14 @@ module Postzord
Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}") Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}")
if self.validate_object if self.validate_object
set_author!
receive_object receive_object
else else
raise 'not a valid object' raise 'not a valid object'
end end
end end
# @return [Object]
def receive_object def receive_object
obj = @object.receive(@user, @author) obj = @object.receive(@user, @author)
Notification.notify(@user, obj, @author) if obj.respond_to?(:notification_type) Notification.notify(@user, obj, @author) if obj.respond_to?(:notification_type)
...@@ -64,34 +66,51 @@ module Postzord ...@@ -64,34 +66,51 @@ module Postzord
end end
def validate_object def validate_object
#begin similar return false if contact_required_unless_request
unless @object.is_a?(Request) || @user.contact_for(@sender) return false if relayable_without_parent?
Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
return false
end
#special casey assign_sender_handle_if_request
if @object.is_a?(Request)
@object.sender_handle = @sender.diaspora_handle return false if author_does_not_match_xml_author?
end
@object
end
def set_author!
return unless @author
@object.author = @author if @object.respond_to? :author=
@object.person = @author if @object.respond_to? :person=
end
private
# abort if we haven't received the post to a comment #validations
def relayable_without_parent?
if @object.respond_to?(:relayable?) && @object.parent.nil? if @object.respond_to?(:relayable?) && @object.parent.nil?
Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})") Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})")
return false return true
end end
end
def author_does_not_match_xml_author?
if (@author.diaspora_handle != xml_author) if (@author.diaspora_handle != xml_author)
Rails.logger.info("event=receive status=abort reason='author in xml does not match retrieved person' payload_type=#{@object.class} recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}") Rails.logger.info("event=receive status=abort reason='author in xml does not match retrieved person' payload_type=#{@object.class} recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
return false return true
end end
end
if @author def contact_required_unless_request
@object.author = @author if @object.respond_to? :author= unless @object.is_a?(Request) || @user.contact_for(@sender)
@object.person = @author if @object.respond_to? :person= Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
return true
end end
end
@object def assign_sender_handle_if_request
#special casey
if @object.is_a?(Request)
@object.sender_handle = @sender.diaspora_handle
end
end end
end end
end end
......
...@@ -64,7 +64,7 @@ describe 'a user receives a post' do ...@@ -64,7 +64,7 @@ describe 'a user receives a post' do
alice.visible_posts.count.should == 1 alice.visible_posts.count.should == 1
end end
context 'mentions' do context 'with mentions, ' do
it 'adds the notifications for the mentioned users regardless of the order they are received' do it 'adds the notifications for the mentioned users regardless of the order they are received' do
Notification.should_receive(:notify).with(alice, anything(), bob.person) Notification.should_receive(:notify).with(alice, anything(), bob.person)
Notification.should_receive(:notify).with(eve, anything(), bob.person) Notification.should_receive(:notify).with(eve, anything(), bob.person)
...@@ -81,7 +81,7 @@ describe 'a user receives a post' do ...@@ -81,7 +81,7 @@ describe 'a user receives a post' do
zord.receive_object zord.receive_object
end end
it 'notifies users when receiving a mention in a post from a remote user' do it 'notifies local users who are mentioned' do
@remote_person = Factory.create(:person, :diaspora_handle => "foobar@foobar.com") @remote_person = Factory.create(:person, :diaspora_handle => "foobar@foobar.com")
Contact.create!(:user => alice, :person => @remote_person, :aspects => [@alices_aspect]) Contact.create!(:user => alice, :person => @remote_person, :aspects => [@alices_aspect])
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter