profile defaults key searchable to true. search takes searchable into account.

This commit is contained in:
danielvincent 2010-11-02 15:32:49 -07:00
parent a6d1906696
commit fff43bf650
7 changed files with 39 additions and 6 deletions

View file

@ -55,6 +55,10 @@ class PeopleController < ApplicationController
params[:person][:profile][:birthday] ||= Date.parse("#{birthday[:year]}-#{birthday[:month]}-#{birthday[:day]}") params[:person][:profile][:birthday] ||= Date.parse("#{birthday[:year]}-#{birthday[:month]}-#{birthday[:day]}")
end 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 # upload and set new profile photo
if params[:person][:profile][:image].present? if params[:person][:profile][:image].present?
raw_image = params[:person][:profile].delete(:image) raw_image = params[:person][:profile].delete(:image)

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

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

@ -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

@ -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

@ -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

@ -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