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