diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index ae00cc7df..a5dd347e5 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index 53f9b3afe..0fe6474aa 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/models/profile.rb b/app/models/profile.rb index d69c64e12..b8383de17 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 870b6ed06..c1c4af9db 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/people/edit.html.haml b/app/views/people/edit.html.haml index d3b8b135d..79440c94e 100644 --- a/app/views/people/edit.html.haml +++ b/app/views/people/edit.html.haml @@ -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') diff --git a/app/views/publics/hcard.erb b/app/views/publics/hcard.erb deleted file mode 100644 index c02d909b5..000000000 --- a/app/views/publics/hcard.erb +++ /dev/null @@ -1,44 +0,0 @@ -
-

<%=@person.real_name%>

-
-
-

User profile

-
-
Nickname
-
- <%= @person.real_name%> -
-
-
-
First name
-
- <%= @person.profile.first_name %> -
-
-
-
Family name
-
- <%= @person.profile.last_name %> -
-
-
-
Full name
-
- <%= @person.real_name %> -
-
-
-
URL
-
- <%= @person.url%> -
-
-
-
Photo
-
- -
-
-
-
-
diff --git a/app/views/publics/hcard.haml b/app/views/publics/hcard.haml new file mode 100644 index 000000000..869286964 --- /dev/null +++ b/app/views/publics/hcard.haml @@ -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 diff --git a/app/views/users/getting_started/_step_1.html.haml b/app/views/users/getting_started/_step_1.html.haml index 6ee900211..56e5638b3 100644 --- a/app/views/users/getting_started/_step_1.html.haml +++ b/app/views/users/getting_started/_step_1.html.haml @@ -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 diff --git a/lib/hcard.rb b/lib/hcard.rb index d02e2b4ec..09acb7c8f 100644 --- a/lib/hcard.rb +++ b/lib/hcard.rb @@ -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 diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index c541f5c41..5577d829f 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -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 + + diff --git a/spec/fixtures/hcard_response b/spec/fixtures/hcard_response index c3bfb2840..d229660d2 100644 --- a/spec/fixtures/hcard_response +++ b/spec/fixtures/hcard_response @@ -43,6 +43,12 @@
Note
Diaspora is awesome! vi is better than emacs!
+
+
Searchable
+
+ false +
+
diff --git a/spec/lib/hcard_spec.rb b/spec/lib/hcard_spec.rb index 7228a1893..fbd4bb42c 100644 --- a/spec/lib/hcard_spec.rb +++ b/spec/lib/hcard_spec.rb @@ -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 diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 498588fa8..4c25b99b3 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -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 diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index b048e9c16..fd27c7203 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 077224674..55c5575fb 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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