Commit 4e2c36f72e7913f3f17d2adccd0813e24b9166eb

Authored by Larissa Reis
1 parent abc047d1

Filter out community members

app/controllers/public/invite_controller.rb
... ... @@ -81,6 +81,7 @@ class InviteController < PublicController
81 81 fields = %w[name identifier email] + plugins_options.map {|field| field[:field].to_s }
82 82 values = ["%#{params['q']}%"] * fields.count
83 83 render :text => environment.people.find(:all, :joins => ['INNER JOIN users ON profiles.user_id=users.id'], :conditions => [fields.map {|field| "LOWER(#{field}) LIKE ?"}.join(' OR '), *values]).
  84 + select {|person| !profile.members.include?(person) }.
84 85 map {|person| {:id => person.id, :name => person.name} }.to_json
85 86 end
86 87  
... ...
test/functional/invite_controller_test.rb
... ... @@ -255,6 +255,20 @@ class InviteControllerTest < ActionController::TestCase
255 255 assert_equal [{"name" => friend1.name, "id" => friend1.id}, {"name" => friend2.name, "id" => friend2.id}].to_json, @response.body
256 256 end
257 257  
  258 + should 'not include members in search friends profiles' do
  259 + community.add_admin(profile)
  260 + friend1 = create_user('willy').person
  261 + friend2 = create_user('william').person
  262 + friend1.save
  263 + friend2.save
  264 +
  265 + community.add_member(friend2)
  266 +
  267 + get :search_friend, :profile => community.identifier, :q => 'will'
  268 +
  269 + assert_equal [{"name" => friend1.name, "id" => friend1.id}].to_json, @response.body
  270 + end
  271 +
258 272 should 'search friends profiles by fields provided by plugins' do
259 273 class Plugin1 < Noosfero::Plugin
260 274 def search_friend_fields
... ...