diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index ea56ed81b4f6ba571c370c631d6e8174505b9935..b82dcce18dc28937dce93984cc46df6791f40244 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -55,6 +55,10 @@ class PeopleController < ApplicationController params[:person][:profile][:birthday] ||= Date.parse("#{birthday[:year]}-#{birthday[:month]}-#{birthday[:day]}") end + search_flag = params[:person][:searchable] + search_flag.to_s.match(/(true)/) ? search_flag = true : search_flag = false + params[:person][:searchable] = search_flag + # upload and set new profile photo if params[:person][:profile][:image].present? raw_image = params[:person][:profile].delete(:image) diff --git a/app/models/person.rb b/app/models/person.rb index 53f9b3afefa59c3faa3fd7b8a6cc722d6f232db3..890b2a52723e1e6868730ce409dfd739186b8701 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 diff --git a/app/models/profile.rb b/app/models/profile.rb index d69c64e1253674d0840145f414d4e4f120bd4b1b..b8383de176c5a776f0faac7f432e52cc3e27019d 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/views/people/edit.html.haml b/app/views/people/edit.html.haml index d3b8b135d157e8432d9b7073863de6ec696b570d..79440c94e115a2d554365c954379afd19167b3cd 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/users/getting_started/_step_1.html.haml b/app/views/users/getting_started/_step_1.html.haml index 6ee9002117bfeacf73beb9743d34982d913f768c..56e5638b37c5b009d02cb2bab9325c38f6dda61b 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/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index c541f5c417044a000c814a11c51c3c7f0681a936..5577d829f6b2c44b7743bff6766ba95a5a16ab11 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/models/person_spec.rb b/spec/models/person_spec.rb index 498588fa85e8350d0ec031b5b8aed7a6a9d57841..4c25b99b34d4e45116bab83f855f860762a87efd 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