Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
8c89f8d87a
15 changed files with 132 additions and 86 deletions
|
|
@ -11,7 +11,7 @@ class PublicsController < ApplicationController
|
|||
def hcard
|
||||
@person = Person.find_by_id params[:id]
|
||||
unless @person.nil? || @person.owner.nil?
|
||||
render 'hcard'
|
||||
render 'publics/hcard'
|
||||
else
|
||||
render :nothing => true, :status => 404
|
||||
end
|
||||
|
|
|
|||
|
|
@ -43,8 +43,10 @@ class Person
|
|||
|
||||
ensure_index :diaspora_handle
|
||||
|
||||
scope :searchable, where('profile.searchable' => true)
|
||||
|
||||
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(" ")
|
||||
full_query_text = Regexp.escape(query.to_s.strip)
|
||||
|
||||
|
|
@ -52,8 +54,8 @@ class Person
|
|||
|
||||
query_tokens.each do |token|
|
||||
q = Regexp.escape(token.to_s.strip)
|
||||
p = Person.all('profile.first_name' => /^#{q}/i) \
|
||||
| Person.all('profile.last_name' => /^#{q}/i) \
|
||||
p = Person.searchable.all('profile.first_name' => /^#{q}/i) \
|
||||
| Person.searchable.all('profile.last_name' => /^#{q}/i) \
|
||||
| p
|
||||
end
|
||||
|
||||
|
|
@ -120,7 +122,10 @@ class Person
|
|||
#hcard_profile = HCard.find profile.hcard.first[:href]
|
||||
Rails.logger.info("hcard: #{ hcard.inspect}")
|
||||
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
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,25 +8,27 @@ class Profile
|
|||
include Diaspora::Webhooks
|
||||
include ROXML
|
||||
|
||||
xml_reader :diaspora_handle
|
||||
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
|
||||
xml_reader :searchable
|
||||
|
||||
key :diaspora_handle, String
|
||||
key :first_name, String
|
||||
key :last_name, String
|
||||
key :image_url, String
|
||||
key :birthday, Date
|
||||
key :gender, String
|
||||
key :bio, String
|
||||
key :diaspora_handle, String
|
||||
key :searchable, Boolean, :default => true
|
||||
|
||||
after_validation :strip_names
|
||||
validates_length_of :first_name, :maximum => 32
|
||||
validates_length_of :last_name, :maximum => 32
|
||||
validates_length_of :last_name, :maximum => 32
|
||||
|
||||
before_save :strip_names
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,11 @@ class User
|
|||
#after_create :seed_aspects
|
||||
|
||||
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
|
||||
if username.present?
|
||||
|
|
@ -401,16 +406,22 @@ class User
|
|||
|
||||
###Helpers############
|
||||
def self.build(opts = {})
|
||||
u = User.new(opts)
|
||||
|
||||
u.username = opts[:username]
|
||||
u.email = opts[:email]
|
||||
|
||||
opts[:person] ||= {}
|
||||
opts[:person][:profile] ||= Profile.new
|
||||
opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}"
|
||||
opts[:person][:url] = APP_CONFIG[:pod_url]
|
||||
u.person = Person.new(opts[:person])
|
||||
u.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}"
|
||||
|
||||
opts[:serialized_private_key] = generate_key
|
||||
opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key
|
||||
u.person.url = APP_CONFIG[:pod_url]
|
||||
|
||||
new_key = generate_key
|
||||
u.serialized_private_key = new_key
|
||||
u.person.serialized_public_key = new_key.public_key
|
||||
|
||||
u = User.new(opts)
|
||||
u
|
||||
end
|
||||
|
||||
|
|
@ -432,7 +443,8 @@ class User
|
|||
|
||||
|
||||
def self.generate_key
|
||||
OpenSSL::PKey::RSA::generate 4096
|
||||
key_size = (Rails.env == 'test' ? 512 : 4096)
|
||||
OpenSSL::PKey::RSA::generate key_size
|
||||
end
|
||||
|
||||
def encryption_key
|
||||
|
|
|
|||
|
|
@ -44,6 +44,12 @@
|
|||
= t('.your_photo')
|
||||
= 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
|
||||
= link_to t('cancel'), edit_user_path(current_user)
|
||||
= t('or')
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
40
app/views/publics/hcard.haml
Normal file
40
app/views/publics/hcard.haml
Normal 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
|
||||
|
|
@ -35,6 +35,12 @@
|
|||
Your photo
|
||||
= 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
|
||||
|
||||
.submit_block
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
module HCard
|
||||
def self.parse doc
|
||||
{
|
||||
:given_name => doc.css(".given_name").text,
|
||||
:given_name => doc.css(".given_name").text,
|
||||
:family_name => doc.css(".family_name").text,
|
||||
:url => doc.css("#pod_location").text,
|
||||
:photo => doc.css(".photo[src]").attribute('src').text
|
||||
:url => doc.css("#pod_location").text,
|
||||
:photo => doc.css(".photo[src]").attribute('src').text,
|
||||
:searchable => doc.css(".searchable").text
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -652,6 +652,11 @@ form p
|
|||
:padding 0
|
||||
:margin 0
|
||||
|
||||
form p.checkbox_select
|
||||
label
|
||||
:left 20px
|
||||
:top 0
|
||||
|
||||
label
|
||||
:font
|
||||
:family 'Arial', 'Helvetica', sans-serif
|
||||
|
|
@ -1450,3 +1455,5 @@ ul.aspects
|
|||
|
||||
:padding
|
||||
:left 120px
|
||||
|
||||
|
||||
|
|
|
|||
6
spec/fixtures/hcard_response
vendored
6
spec/fixtures/hcard_response
vendored
|
|
@ -43,6 +43,12 @@
|
|||
<dt>Note</dt>
|
||||
<dd class="note">Diaspora is awesome! vi is better than emacs!</dd>
|
||||
</dl>
|
||||
<dl class='entity_searchable'>
|
||||
<dt>Searchable</dt>
|
||||
<dd>
|
||||
<span class='searchable'>false</span>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ describe HCard do
|
|||
hcard[:family_name].include?("Hamiltom").should be true
|
||||
hcard[:given_name].include?("Alex").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
|
||||
|
|
|
|||
|
|
@ -187,6 +187,12 @@ describe Person do
|
|||
people = Person.search("Casey Grippi")
|
||||
people.should == [@friend_four]
|
||||
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
|
||||
|
||||
context 'people finders for webfinger' do
|
||||
|
|
|
|||
|
|
@ -92,25 +92,25 @@ describe Photo do
|
|||
|
||||
end
|
||||
|
||||
describe 'remote photos' do
|
||||
it 'should write the url on serialization' 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
|
||||
describe 'serialization' do
|
||||
before do
|
||||
@photo.image.store! File.open(@fixture_name)
|
||||
xml = @photo.to_xml.to_s
|
||||
xml.include?(@photo.album_id.to_s).should be true
|
||||
@xml = @photo.to_xml.to_s
|
||||
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
|
||||
pending "did the socket get unstubbed?"
|
||||
pending "For IZ, MS"
|
||||
@photo.image.store! File.open(@fixture_name)
|
||||
|
||||
|
||||
|
|
@ -118,10 +118,6 @@ describe Photo do
|
|||
user2 = Factory.create(:user)
|
||||
aspect2 = user2.aspects.create(:name => "foobars")
|
||||
friend_users(@user, @aspect, user2, aspect2)
|
||||
@photo.person = user2.person
|
||||
|
||||
@photo.save
|
||||
#@photo.reload
|
||||
|
||||
url = @photo.url
|
||||
thumb_url = @photo.url :thumb_medium
|
||||
|
|
@ -130,7 +126,7 @@ describe Photo do
|
|||
id = @photo.id
|
||||
|
||||
@photo.destroy
|
||||
@user.receive xml, @photo.person
|
||||
user2.receive xml, @user.person
|
||||
|
||||
new_photo = Photo.first(:id => id)
|
||||
new_photo.url.nil?.should be false
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ describe User do
|
|||
new_user.id.should_not == user.id
|
||||
end
|
||||
it 'does not overwrite old users with create' do
|
||||
pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!"
|
||||
params = {:username => "ohai",
|
||||
:email => "ohai@example.com",
|
||||
:password => "password",
|
||||
|
|
@ -163,13 +162,16 @@ describe User do
|
|||
}
|
||||
@user = User.build(params)
|
||||
end
|
||||
it "makes a valid user" do
|
||||
@user.should be_valid
|
||||
it "does not save" do
|
||||
@user.persisted?.should be_false
|
||||
@user.person.persisted?.should be_false
|
||||
User.find_by_username("ohai").should be_nil
|
||||
end
|
||||
it 'saves successfully' do
|
||||
@user.should be_valid
|
||||
@user.save.should be_true
|
||||
@user.persisted?.should be_true
|
||||
@user.person.persisted?.should be_true
|
||||
User.find_by_username("ohai").should == @user
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue