Skip to content

Commit

Permalink
DG MS fixing webfinger, i hope to goodness
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwell committed Sep 15, 2010
1 parent 57bd052 commit 84c60e5
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
The privacy aware, personally controlled, do-it-all, open source social network.

**DISCLAIMER: THIS IS PRE-ALPHA SOFTWARE AND SHOULD BE TREATED ACCORDINGLY.**
These instructions are for machines running [Ubuntu](http://www.ubuntu.com/) or Mac OS X.
These instructions are for machines running [Ubuntu](http://www.ubuntu.com/) or Mac OS X. We are developing Diaspora for the latest and greatest browsers, so please update your Firefox, Chrome or Safari to the latest and greatest.

## Preparing your system
In order to run Diaspora, you will need to download the following dependencies (specific instructions follow):
Expand Down
15 changes: 8 additions & 7 deletions app/models/person.rb
Expand Up @@ -11,13 +11,13 @@ class Person
include Encryptor::Public

xml_accessor :_id
xml_accessor :email
xml_accessor :diaspora_handle
xml_accessor :url
xml_accessor :profile, :as => Profile
xml_reader :exported_key

key :url, String
key :email, String, :unique => true
key :diaspora_handle, String, :unique => true
key :serialized_key, String

key :owner_id, ObjectId
Expand All @@ -30,13 +30,13 @@ class Person

before_destroy :remove_all_traces
before_validation :clean_url
validates_presence_of :email, :url, :profile, :serialized_key
validates_presence_of :diaspora_handle, :url, :profile, :serialized_key
validates_format_of :url, :with =>
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix


def self.search(query)
Person.all('$where' => "function() { return this.email.match(/^#{query}/i) ||
Person.all('$where' => "function() { return this.diaspora_handle.match(/^#{query}/i) ||
this.profile.first_name.match(/^#{query}/i) ||
this.profile.last_name.match(/^#{query}/i); }")
end
Expand Down Expand Up @@ -79,7 +79,8 @@ def exported_key= new_key
end

def self.by_webfinger( identifier )
local_person = Person.first(:email => identifier.gsub('acct:', ''))
local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', ''))

if local_person
local_person
elsif !identifier.include?("localhost")
Expand All @@ -102,7 +103,7 @@ def self.from_webfinger_profile( identifier, profile)
guid = profile.links.select{|x| x.rel == 'http://joindiaspora.com/guid'}.first.href
new_person.id = guid

new_person.email = identifier
new_person.diaspora_handle = identifier

hcard = HCard.find profile.hcard.first[:href]

Expand All @@ -124,7 +125,7 @@ def as_json(opts={})
:person => {
:id => self.id,
:name => self.real_name,
:email => self.email,
:diaspora_handle => self.diaspora_handle,
:url => self.url,
:exported_key => exported_key
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -305,7 +305,7 @@ def do_bad_things

def setup_person
self.person.serialized_key ||= User.generate_key.export
self.person.email ||= email
self.person.diaspora_handle ||= self.diaspora_handle
self.person.save!
end

Expand Down
6 changes: 3 additions & 3 deletions app/views/people/index.html.haml
Expand Up @@ -18,7 +18,7 @@
%table
%tr
%th real name
%th email
%th diaspora handle
%th url
- for person in @people
%tr
Expand All @@ -27,7 +27,7 @@
- else
%td= person.real_name

%td= person.email
%td= person.diaspora_handle
%td= person.url

-if current_user.friends.include? person
Expand All @@ -46,5 +46,5 @@
%td
= form_for Request.new do |f|
= f.select(:aspect_id, @aspects_dropdown_array)
= f.hidden_field :destination_url, :value => person.email
= f.hidden_field :destination_url, :value => person.diaspora_handle
= f.submit "add friend"
4 changes: 2 additions & 2 deletions app/views/people/new.html.haml
Expand Up @@ -8,9 +8,9 @@
= form_for @person do |f|
= f.error_messages
%p
= f.label :email
= f.label :diaspora_handle
%br
= f.text_field :email
= f.text_field :diaspora_handle
%p
= f.label :url
%br
Expand Down
2 changes: 1 addition & 1 deletion app/views/publics/webfinger.erb
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Subject>acct:<%=@person.email%></Subject>
<Subject>acct:<%=@person.diaspora_handle%></Subject>
<Alias>"<%= @person.url %>"</Alias>
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="<%=@person.url%>hcard/users/<%=@person.id%>"/>
<Link rel="http://joindiaspora.com/seed_location" type = 'text/html' href="<%=@person.url%>"/>
Expand Down
2 changes: 1 addition & 1 deletion lib/salmon/salmon.rb
Expand Up @@ -82,7 +82,7 @@ def to_xml
<entry xmlns='http://www.w3.org/2005/Atom'>
<author>
<name>#{@author.real_name}</name>
<uri>acct:#{@author.email}</uri>
<uri>acct:#{@author.diaspora_handle}</uri>
</author>
#{@magic_sig.to_xml}
</entry>
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/publics_controller_spec.rb
Expand Up @@ -60,7 +60,7 @@
end

it 'should add the pending request to the right user if the target person does not exist locally' do
Person.should_receive(:by_webfinger).with(@user2.person.email).and_return(@user2.person)
Person.should_receive(:by_webfinger).with(@user2.person.diaspora_handle).and_return(@user2.person)
@user2.person.delete
@user2.delete
post :receive, :id => @user.person.id, :xml => @xml
Expand Down
2 changes: 1 addition & 1 deletion spec/factories.rb
Expand Up @@ -15,7 +15,7 @@
end

Factory.define :person do |p|
p.sequence(:email) {|n| "bob-person-#{n}@aol.com"}
p.sequence(:diaspora_handle) {|n| "bob-person-#{n}@aol.com"}
p.sequence(:url) {|n| "http://google-#{n}.com/"}
p.profile Factory.create(:profile)

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/msg.xml.clear.asc
Expand Up @@ -5,7 +5,7 @@ Hash: SHA1
<message>jimmy's 1 whales</message>
<_id>4c3b7cf9312f91367f000004</_id>
<person>
<email>bob1@aol.com</email>
<diaspora_handle>bob1@aol.com</diaspora_handle>
<url>http://www.example.com/</url>
<_id>4c3b7c64312f913664000005</_id>
<key_fingerprint>0264242496D4B585297BF236BEEFE6DEBE3407AA</key_fingerprint>
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/diaspora_parser_spec.rb
Expand Up @@ -15,7 +15,7 @@
before do
@user = Factory.create(:user, :email => "bob@aol.com")
@aspect = @user.aspect(:name => 'spies')
@person = Factory.create(:person_with_private_key, :email => "bill@gates.com")
@person = Factory.create(:person_with_private_key, :diaspora_handle => "bill@gates.com")
@user2 = Factory.create(:user)
end

Expand All @@ -25,7 +25,7 @@
end

it 'should be able to correctly handle comments with person in db' do
person = Factory.create(:person, :email => "test@testing.com")
person = Factory.create(:person, :diaspora_handle => "test@testing.com")
post = Factory.create(:status_message, :person => @user.person)
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
xml = comment.to_diaspora_xml
Expand All @@ -49,7 +49,7 @@

parsed_person = Diaspora::Parser::parse_or_find_person_from_xml(xml)
parsed_person.save.should be true
parsed_person.email.should == commenter.person.email
parsed_person.diaspora_handle.should == commenter.person.diaspora_handle
parsed_person.profile.should_not be_nil
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/salmon_salmon_spec.rb
Expand Up @@ -35,8 +35,8 @@
@parsed_salmon.data.should == xml
end

it 'should parse out the author email' do
@parsed_salmon.author_email.should == @user.person.email
it 'should parse out the authors diaspora_handle' do
@parsed_salmon.author_email.should == @user.person.diaspora_handle
end

it 'should reference a local author' do
Expand Down
8 changes: 4 additions & 4 deletions spec/models/person_spec.rb
Expand Up @@ -15,8 +15,8 @@
@aspect2 = @user2.aspect(:name => "Abscence of Babes")
end

it 'should not allow two people with the same email' do
person_two = Factory.build(:person, :url => @person.email)
it 'should not allow two people with the same diaspora_handle' do
person_two = Factory.build(:person, :url => @person.diaspora_handle)
person_two.valid?.should == false
end

Expand Down Expand Up @@ -147,10 +147,10 @@
people.include?(@friend_three).should == false
end

it 'should search by email exactly' do
it 'should search by diaspora_handle exactly' do

stub_success("tom@tom.joindiaspora.com")
Person.by_webfinger(@friend_one.email).should == @friend_one
Person.by_webfinger(@friend_one.diaspora_handle).should == @friend_one
end

it 'should create a stub for a remote user' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/post_spec.rb
Expand Up @@ -18,7 +18,7 @@
end

it 'should serialize to xml with its person' do
@message.to_xml.to_s.include?(@user.person.email).should == true
@message.to_xml.to_s.include?(@user.person.diaspora_handle).should == true
end

end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/request_spec.rb
Expand Up @@ -25,14 +25,14 @@

xml = request.to_xml.to_s

xml.include?(@user.person.email).should be true
xml.include?(@user.person.diaspora_handle).should be true
xml.include?(@user.url).should be true
xml.include?(@user.profile.first_name).should be true
xml.include?(@user.profile.last_name).should be true
end

it 'should allow me to see only friend requests sent to me' do
remote_person = Factory.build(:person, :email => "robert@grimm.com", :url => "http://king.com/")
remote_person = Factory.build(:person, :diaspora_handle => "robert@grimm.com", :url => "http://king.com/")

Request.instantiate(:into => @aspect.id, :from => @user.person, :to => remote_person.receive_url).save
Request.instantiate(:into => @aspect.id, :from => @user.person, :to => remote_person.receive_url).save
Expand Down
4 changes: 2 additions & 2 deletions spec/user_encryption_spec.rb
Expand Up @@ -16,12 +16,12 @@
@person = Factory.create(:person_with_private_key,
:profile => Profile.new(:first_name => 'Remote',
:last_name => 'Friend'),
:email => 'somewhere@else.com',
:diaspora_handle => 'somewhere@else.com',
:url => 'http://distant-example.com/')
@person2 = Factory.create(:person_with_private_key,
:profile => Profile.new(:first_name => 'Second',
:last_name => 'Friend'),
:email => 'elsewhere@else.com',
:diaspora_handle => 'elsewhere@else.com',
:url => 'http://distanter-example.com/')
end

Expand Down

0 comments on commit 84c60e5

Please sign in to comment.