MS IZ everything now uses diaspora handle. this feels so good
This commit is contained in:
parent
7244730961
commit
15d6cff837
4 changed files with 50 additions and 61 deletions
30
Gemfile.lock
30
Gemfile.lock
|
|
@ -115,6 +115,7 @@ GEM
|
|||
activesupport (= 3.0.1)
|
||||
activesupport (3.0.1)
|
||||
addressable (2.2.2)
|
||||
archive-tar-minitar (0.5.2)
|
||||
arel (1.0.1)
|
||||
activesupport (~> 3.0.0)
|
||||
aws (2.3.24)
|
||||
|
|
@ -140,7 +141,6 @@ GEM
|
|||
rack (>= 1.0.0)
|
||||
rack-test (>= 0.5.4)
|
||||
selenium-webdriver (>= 0.0.3)
|
||||
cgi_multipart_eof_fix (2.5.0)
|
||||
chef (0.9.12)
|
||||
bunny (>= 0.6.0)
|
||||
erubis
|
||||
|
|
@ -192,10 +192,8 @@ GEM
|
|||
addressable (~> 2.2.2)
|
||||
multipart-post (~> 1.0.1)
|
||||
rack (>= 1.1.0, < 2)
|
||||
fastthread (1.0.7)
|
||||
ffi (0.6.3)
|
||||
rake (>= 0.8.7)
|
||||
gem_plugin (0.2.3)
|
||||
gherkin (2.2.9)
|
||||
json (~> 1.4.6)
|
||||
term-ansicolor (~> 1.0.5)
|
||||
|
|
@ -211,7 +209,8 @@ GEM
|
|||
launchy (0.3.7)
|
||||
configuration (>= 0.0.5)
|
||||
rake (>= 0.8.1)
|
||||
linecache (0.43)
|
||||
linecache19 (0.5.11)
|
||||
ruby_core_source (>= 0.1.4)
|
||||
mail (2.2.9)
|
||||
activesupport (>= 2.3.6)
|
||||
i18n (~> 0.4.1)
|
||||
|
|
@ -233,11 +232,6 @@ GEM
|
|||
moneta (0.6.0)
|
||||
mongo (1.1)
|
||||
bson (>= 1.0.5)
|
||||
mongrel (1.1.5)
|
||||
cgi_multipart_eof_fix (>= 2.4)
|
||||
daemons (>= 1.0.3)
|
||||
fastthread (>= 1.0.1)
|
||||
gem_plugin (>= 0.2.3)
|
||||
multi_json (0.0.4)
|
||||
multipart-post (1.0.1)
|
||||
net-ldap (0.1.1)
|
||||
|
|
@ -332,14 +326,19 @@ GEM
|
|||
rspec-expectations (~> 2.0.1)
|
||||
rspec-rails (2.0.1)
|
||||
rspec (~> 2.0.0)
|
||||
ruby-debug (0.10.3)
|
||||
columnize (>= 0.1)
|
||||
ruby-debug-base (~> 0.10.3.0)
|
||||
ruby-debug-base (0.10.3)
|
||||
linecache (>= 0.3)
|
||||
ruby-debug-base19 (0.11.24)
|
||||
columnize (>= 0.3.1)
|
||||
linecache19 (>= 0.5.11)
|
||||
ruby_core_source (>= 0.1.4)
|
||||
ruby-debug19 (0.11.6)
|
||||
columnize (>= 0.3.1)
|
||||
linecache19 (>= 0.5.11)
|
||||
ruby-debug-base19 (>= 0.11.19)
|
||||
ruby-openid (2.1.8)
|
||||
ruby-openid-apps-discovery (1.2.0)
|
||||
ruby-openid (>= 2.1.7)
|
||||
ruby_core_source (0.1.4)
|
||||
archive-tar-minitar (>= 0.5.2)
|
||||
rubyntlm (0.1.1)
|
||||
rubyzip (0.9.4)
|
||||
selenium-client (1.2.18)
|
||||
|
|
@ -405,7 +404,6 @@ DEPENDENCIES
|
|||
mini_magick
|
||||
mocha
|
||||
mongo_mapper!
|
||||
mongrel
|
||||
omniauth
|
||||
pubsubhubbub
|
||||
rails (>= 3.0.0)
|
||||
|
|
@ -413,7 +411,7 @@ DEPENDENCIES
|
|||
roxml!
|
||||
rspec (>= 2.0.0)
|
||||
rspec-rails (>= 2.0.0)
|
||||
ruby-debug
|
||||
ruby-debug19
|
||||
sprinkle!
|
||||
thin
|
||||
twitter
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ class Profile
|
|||
include Diaspora::Webhooks
|
||||
include ROXML
|
||||
|
||||
xml_reader :person_id
|
||||
xml_reader :first_name
|
||||
xml_reader :last_name
|
||||
xml_reader :image_url
|
||||
xml_reader :birthday
|
||||
xml_reader :gender
|
||||
xml_reader :bio
|
||||
xml_accessor :diaspora_handle
|
||||
|
||||
key :first_name, String
|
||||
key :last_name, String
|
||||
|
|
@ -22,6 +22,7 @@ class Profile
|
|||
key :birthday, Date
|
||||
key :gender, String
|
||||
key :bio, String
|
||||
key :diaspora_handle, String
|
||||
|
||||
after_validation :strip_names
|
||||
validates_length_of :first_name, :maximum => 32
|
||||
|
|
@ -29,14 +30,15 @@ class Profile
|
|||
|
||||
before_save :strip_names
|
||||
|
||||
def person_id
|
||||
self._parent_document.id
|
||||
end
|
||||
|
||||
def person
|
||||
self._parent_document
|
||||
end
|
||||
|
||||
def diaspora_handle
|
||||
#get the parent diaspora handle, unless we want to access a profile without a person
|
||||
(self._parent_document) ? self.person.diaspora_handle : self[:diaspora_handle]
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def strip_names
|
||||
|
|
|
|||
|
|
@ -18,69 +18,48 @@ module Diaspora
|
|||
def receive xml, salmon_author
|
||||
object = Diaspora::Parser.from_xml(xml)
|
||||
Rails.logger.debug("Receiving object for #{self.real_name}:\n#{object.inspect}")
|
||||
Rails.logger.debug("From: #{object.person.inspect}") if object.person
|
||||
Rails.logger.debug("From: #{object.diaspora_handle}")
|
||||
|
||||
if object.is_a?(Comment)
|
||||
xml_author = (owns?(object.post))? object.diaspora_handle : object.post.person.diaspora_handle
|
||||
else
|
||||
xml_author = object.diaspora_handle
|
||||
end
|
||||
|
||||
if (salmon_author.diaspora_handle != xml_author)
|
||||
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{xml_author} "
|
||||
end
|
||||
|
||||
if object.is_a?(Comment) || object.is_a?(Post)|| object.is_a?(Request) || object.is_a?(Retraction)
|
||||
if object.is_a?(Comment) || object.is_a?(Post)|| object.is_a?(Request) || object.is_a?(Retraction) || object.is_a?(Profile)
|
||||
e = EMWebfinger.new(object.diaspora_handle)
|
||||
|
||||
e.on_person { |person|
|
||||
|
||||
if person.class == Person
|
||||
object.person = person
|
||||
|
||||
sender_in_xml = sender(object, xml, person)
|
||||
if (salmon_author != sender_in_xml)
|
||||
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
|
||||
end
|
||||
object.person = person if object.respond_to? :person=
|
||||
|
||||
if object.is_a? Request
|
||||
return receive_request object, sender_in_xml
|
||||
return receive_request object, person
|
||||
end
|
||||
|
||||
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
||||
|
||||
if object.is_a?(Comment)
|
||||
receive_comment object, xml
|
||||
elsif object.is_a? Retraction
|
||||
elsif object.is_a?(Retraction)
|
||||
receive_retraction object, xml
|
||||
elsif object.is_a?(Profile)
|
||||
receive_profile object, person
|
||||
else
|
||||
receive_post object, xml
|
||||
end
|
||||
|
||||
end
|
||||
}
|
||||
|
||||
else
|
||||
sender_in_xml = sender(object, xml)
|
||||
|
||||
if (salmon_author != sender_in_xml)
|
||||
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
|
||||
end
|
||||
|
||||
raise "Not friends with that person" unless self.contact_for(salmon_author)
|
||||
|
||||
|
||||
if object.is_a? Profile
|
||||
receive_profile object, xml
|
||||
end
|
||||
raise "you messed up"
|
||||
end
|
||||
end
|
||||
|
||||
def sender(object, xml, webfingered_person = nil)
|
||||
if object.is_a? Profile
|
||||
sender = Diaspora::Parser.owner_id_from_xml xml
|
||||
|
||||
else
|
||||
if object.is_a?(Comment)
|
||||
sender = (owns?(object.post))? object.person : object.post.person
|
||||
else
|
||||
sender = object.person
|
||||
end
|
||||
end
|
||||
sender
|
||||
end
|
||||
|
||||
def receive_retraction retraction, xml
|
||||
if retraction.type == 'Person'
|
||||
unless retraction.person.id.to_s == retraction.post_id.to_s
|
||||
|
|
@ -107,8 +86,7 @@ module Diaspora
|
|||
receive_friend_request(request)
|
||||
end
|
||||
|
||||
def receive_profile profile, xml
|
||||
person = Diaspora::Parser.owner_id_from_xml xml
|
||||
def receive_profile profile, person
|
||||
person.profile = profile
|
||||
person.save
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,4 +41,15 @@ describe Profile do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'serialization' do
|
||||
let(:person) {Factory.create(:person)}
|
||||
|
||||
it 'should include persons diaspora handle' do
|
||||
xml = person.profile.to_diaspora_xml
|
||||
|
||||
xml.should include person.diaspora_handle
|
||||
xml.should_not include person.id.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue