Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
maxwell 2010-11-02 16:42:52 -07:00
commit 8c89f8d87a
15 changed files with 132 additions and 86 deletions

View file

@ -11,7 +11,7 @@ class PublicsController < ApplicationController
def hcard def hcard
@person = Person.find_by_id params[:id] @person = Person.find_by_id params[:id]
unless @person.nil? || @person.owner.nil? unless @person.nil? || @person.owner.nil?
render 'hcard' render 'publics/hcard'
else else
render :nothing => true, :status => 404 render :nothing => true, :status => 404
end end

View file

@ -43,8 +43,10 @@ class Person
ensure_index :diaspora_handle ensure_index :diaspora_handle
scope :searchable, where('profile.searchable' => true)
def self.search(query) def self.search(query)
return Person.all if query.to_s.empty? return Person.searchable.all if query.to_s.empty?
query_tokens = query.to_s.strip.split(" ") query_tokens = query.to_s.strip.split(" ")
full_query_text = Regexp.escape(query.to_s.strip) full_query_text = Regexp.escape(query.to_s.strip)
@ -52,8 +54,8 @@ class Person
query_tokens.each do |token| query_tokens.each do |token|
q = Regexp.escape(token.to_s.strip) q = Regexp.escape(token.to_s.strip)
p = Person.all('profile.first_name' => /^#{q}/i) \ p = Person.searchable.all('profile.first_name' => /^#{q}/i) \
| Person.all('profile.last_name' => /^#{q}/i) \ | Person.searchable.all('profile.last_name' => /^#{q}/i) \
| p | p
end end
@ -120,7 +122,10 @@ class Person
#hcard_profile = HCard.find profile.hcard.first[:href] #hcard_profile = HCard.find profile.hcard.first[:href]
Rails.logger.info("hcard: #{ hcard.inspect}") Rails.logger.info("hcard: #{ hcard.inspect}")
new_person.url = hcard[:url] new_person.url = hcard[:url]
new_person.profile = Profile.new(:first_name => hcard[:given_name], :last_name => hcard[:family_name], :image_url => hcard[:photo]) new_person.profile = Profile.new( :first_name => hcard[:given_name],
:last_name => hcard[:family_name],
:image_url => hcard[:photo],
:searchable => hcard[:searchable])
new_person.save! ? new_person : nil new_person.save! ? new_person : nil
end end

View file

@ -8,21 +8,23 @@ class Profile
include Diaspora::Webhooks include Diaspora::Webhooks
include ROXML include ROXML
xml_reader :diaspora_handle
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 xml_reader :searchable
key :diaspora_handle, String
key :first_name, String key :first_name, String
key :last_name, String key :last_name, String
key :image_url, String key :image_url, String
key :birthday, Date key :birthday, Date
key :gender, String key :gender, String
key :bio, String key :bio, String
key :diaspora_handle, String key :searchable, Boolean, :default => true
after_validation :strip_names after_validation :strip_names
validates_length_of :first_name, :maximum => 32 validates_length_of :first_name, :maximum => 32

View file

@ -60,6 +60,11 @@ class User
#after_create :seed_aspects #after_create :seed_aspects
before_destroy :unfriend_everyone, :remove_person before_destroy :unfriend_everyone, :remove_person
before_save do
person.save if person
end
attr_accessible :getting_started, :password, :password_confirmation, :language,
def strip_and_downcase_username def strip_and_downcase_username
if username.present? if username.present?
@ -401,16 +406,22 @@ class User
###Helpers############ ###Helpers############
def self.build(opts = {}) def self.build(opts = {})
u = User.new(opts)
u.username = opts[:username]
u.email = opts[:email]
opts[:person] ||= {} opts[:person] ||= {}
opts[:person][:profile] ||= Profile.new opts[:person][:profile] ||= Profile.new
opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}" u.person = Person.new(opts[:person])
opts[:person][:url] = APP_CONFIG[:pod_url] u.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}"
opts[:serialized_private_key] = generate_key u.person.url = APP_CONFIG[:pod_url]
opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key
new_key = generate_key
u.serialized_private_key = new_key
u.person.serialized_public_key = new_key.public_key
u = User.new(opts)
u u
end end
@ -432,7 +443,8 @@ class User
def self.generate_key def self.generate_key
OpenSSL::PKey::RSA::generate 4096 key_size = (Rails.env == 'test' ? 512 : 4096)
OpenSSL::PKey::RSA::generate key_size
end end
def encryption_key def encryption_key

View file

@ -44,6 +44,12 @@
= t('.your_photo') = t('.your_photo')
= render 'people/profile_photo_upload', :form => profile = render 'people/profile_photo_upload', :form => profile
%h4
Search
%p{:class=>"checkbox_select"}
= profile.label :searchable, "Allow for people to search for you"
= profile.check_box :searchable, {:checked => @person.profile.searchable}, true, false
.submit_block .submit_block
= link_to t('cancel'), edit_user_path(current_user) = link_to t('cancel'), edit_user_path(current_user)
= t('or') = t('or')

View file

@ -1,44 +0,0 @@
<div id="content">
<h1><%=@person.real_name%></h1>
<div id="content_inner">
<div id="i" class="entity_profile vcard author">
<h2>User profile</h2>
<dl class="entity_nickname">
<dt>Nickname</dt>
<dd>
<a href="<%=@person.url%>" rel="me" class="nickname url uid"><%= @person.real_name%></a>
</dd>
</dl>
<dl class="entity_given_name">
<dt>First name</dt>
<dd>
<span class="given_name" ><%= @person.profile.first_name %></span>
</dd>
</dl>
<dl class="entity_family_name">
<dt>Family name</dt>
<dd>
<span class="family_name" ><%= @person.profile.last_name %></span>
</dd>
</dl>
<dl class="entity_fn">
<dt>Full name</dt>
<dd>
<span class="fn" ><%= @person.real_name %></span>
</dd>
</dl>
<dl class="entity_url">
<dt>URL</dt>
<dd>
<a href="<%= @person.url%>" rel="me" id="pod_location" class="url"><%= @person.url%></a>
</dd>
</dl>
<dl class="entity_photo">
<dt>Photo</dt>
<dd>
<img class="photo avatar" src="<%= image_or_default(@person)%>" width="100" height="100"/>
</dd>
</dl>
</div>
</div>
</div>

View file

@ -0,0 +1,40 @@
#content
%h1= @person.real_name
#content_inner
#i.entity_profile.vcard.author
%h2 User profile
%dl.entity_nickname
%dt Nickname
%dd
%a.nickname.url.uid{:href=>@person.url, :rel=>'me'}= @person.real_name
%dl.entity_given_name
%dt First name
%dd
%span.given_name= @person.profile.first_name
%dl.entity_family_name
%dt Family name
%dd
%span.family_name= @person.profile.last_name
%dl.entity_fn
%dt Full name
%dd
%span.fn= @person.real_name
%dl.entity_url
%dt URL
%dd
%a#pod_location.url{:href=>@person.url, :rel=>'me'}= @person.url
%dl.entity_photo
%dt Photo
%dd
%img.photo.avatar{:src=>image_or_default(@person), :width=>'100px', :height=>'100px'}
%dl.entity_searchable
%dt Searchable
%dd
%span.searchable= @person.profile.searchable

View file

@ -35,6 +35,12 @@
Your photo Your photo
= render 'people/profile_photo_upload', :form => profile = render 'people/profile_photo_upload', :form => profile
%h4
Search
%p{:class=>"checkbox_select"}
= profile.label :searchable, "Allow for people to search for you"
= profile.check_box :searchable, {:checked => @person.profile.searchable}, true, false
= hidden_field_tag :getting_started, @step = hidden_field_tag :getting_started, @step
.submit_block .submit_block

View file

@ -8,7 +8,8 @@ module HCard
:given_name => doc.css(".given_name").text, :given_name => doc.css(".given_name").text,
:family_name => doc.css(".family_name").text, :family_name => doc.css(".family_name").text,
:url => doc.css("#pod_location").text, :url => doc.css("#pod_location").text,
:photo => doc.css(".photo[src]").attribute('src').text :photo => doc.css(".photo[src]").attribute('src').text,
:searchable => doc.css(".searchable").text
} }
end end

View file

@ -652,6 +652,11 @@ form p
:padding 0 :padding 0
:margin 0 :margin 0
form p.checkbox_select
label
:left 20px
:top 0
label label
:font :font
:family 'Arial', 'Helvetica', sans-serif :family 'Arial', 'Helvetica', sans-serif
@ -1450,3 +1455,5 @@ ul.aspects
:padding :padding
:left 120px :left 120px

View file

@ -43,6 +43,12 @@
<dt>Note</dt> <dt>Note</dt>
<dd class="note">Diaspora is awesome! vi is better than emacs!</dd> <dd class="note">Diaspora is awesome! vi is better than emacs!</dd>
</dl> </dl>
<dl class='entity_searchable'>
<dt>Searchable</dt>
<dd>
<span class='searchable'>false</span>
</dd>
</dl>
</div> </div>
</div> </div>
</div> </div>

View file

@ -13,5 +13,6 @@ describe HCard do
hcard[:given_name].include?("Alex").should be true hcard[:given_name].include?("Alex").should be true
hcard[:photo].include?("tom.jpg").should be true hcard[:photo].include?("tom.jpg").should be true
hcard[:url].should == "http://tom.joindiaspora.com/" hcard[:url].should == "http://tom.joindiaspora.com/"
hcard[:searchable].should == "false"
end end
end end

View file

@ -187,6 +187,12 @@ describe Person do
people = Person.search("Casey Grippi") people = Person.search("Casey Grippi")
people.should == [@friend_four] people.should == [@friend_four]
end end
it 'should only display searchable people' do
invisible_person = Factory(:person, :profile => {:searchable => false, :first_name => "johnson"})
Person.search("johnson").should_not include invisible_person
Person.search("").should_not include invisible_person
end
end end
context 'people finders for webfinger' do context 'people finders for webfinger' do

View file

@ -92,25 +92,25 @@ describe Photo do
end end
describe 'remote photos' do describe 'serialization' do
it 'should write the url on serialization' do before do
@photo.image = File.open(@fixture_name)
@photo.image.store!
@photo.save
xml = @photo.to_xml.to_s
xml.include?(@photo.image.url).should be true
end
it 'should have an album id on serialization' do
@photo.image.store! File.open(@fixture_name) @photo.image.store! File.open(@fixture_name)
xml = @photo.to_xml.to_s @xml = @photo.to_xml.to_s
xml.include?(@photo.album_id.to_s).should be true
end end
it 'serializes the url' do
@xml.include?(@photo.image.url).should be true
end
it 'serializes the album_id' do
@xml.include?(@photo.album_id.to_s).should be true
end
it 'serializes the diaspora_handle' do
pending "For IZ, MS"
@xml.include?(@user.diaspora_handle).should be true
end
end
describe 'remote photos' do
it 'should set the remote_photo on marshalling' do it 'should set the remote_photo on marshalling' do
pending "did the socket get unstubbed?" pending "For IZ, MS"
@photo.image.store! File.open(@fixture_name) @photo.image.store! File.open(@fixture_name)
@ -118,10 +118,6 @@ describe Photo do
user2 = Factory.create(:user) user2 = Factory.create(:user)
aspect2 = user2.aspects.create(:name => "foobars") aspect2 = user2.aspects.create(:name => "foobars")
friend_users(@user, @aspect, user2, aspect2) friend_users(@user, @aspect, user2, aspect2)
@photo.person = user2.person
@photo.save
#@photo.reload
url = @photo.url url = @photo.url
thumb_url = @photo.url :thumb_medium thumb_url = @photo.url :thumb_medium
@ -130,7 +126,7 @@ describe Photo do
id = @photo.id id = @photo.id
@photo.destroy @photo.destroy
@user.receive xml, @photo.person user2.receive xml, @user.person
new_photo = Photo.first(:id => id) new_photo = Photo.first(:id => id)
new_photo.url.nil?.should be false new_photo.url.nil?.should be false

View file

@ -22,7 +22,6 @@ describe User do
new_user.id.should_not == user.id new_user.id.should_not == user.id
end end
it 'does not overwrite old users with create' do it 'does not overwrite old users with create' do
pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!"
params = {:username => "ohai", params = {:username => "ohai",
:email => "ohai@example.com", :email => "ohai@example.com",
:password => "password", :password => "password",
@ -163,13 +162,16 @@ describe User do
} }
@user = User.build(params) @user = User.build(params)
end end
it "makes a valid user" do it "does not save" do
@user.should be_valid
@user.persisted?.should be_false @user.persisted?.should be_false
@user.person.persisted?.should be_false
User.find_by_username("ohai").should be_nil User.find_by_username("ohai").should be_nil
end end
it 'saves successfully' do it 'saves successfully' do
@user.should be_valid
@user.save.should be_true @user.save.should be_true
@user.persisted?.should be_true
@user.person.persisted?.should be_true
User.find_by_username("ohai").should == @user User.find_by_username("ohai").should == @user
end end
end end