Exclude closed accounts from search

closes #7042
This commit is contained in:
Steffen van Bergerem 2016-08-31 03:02:01 +02:00 committed by Dennis Schubert
parent 9a2cb1517a
commit 806de7e9d8
No known key found for this signature in database
GPG key ID: 5A0304BEA7966D7E
5 changed files with 65 additions and 11 deletions

View file

@ -7,6 +7,7 @@
## Bug fixes ## Bug fixes
* Post comments no longer get collapsed when interacting with a post [#7040](https://github.com/diaspora/diaspora/pull/7040) * Post comments no longer get collapsed when interacting with a post [#7040](https://github.com/diaspora/diaspora/pull/7040)
* Closed accounts will no longer show up in the account search [#7042](https://github.com/diaspora/diaspora/pull/7042)
## Features ## Features
* Deleted comments will be removed when loading more comments [#7045](https://github.com/diaspora/diaspora/pull/7045) * Deleted comments will be removed when loading more comments [#7045](https://github.com/diaspora/diaspora/pull/7045)

View file

@ -41,7 +41,7 @@ class PeopleController < ApplicationController
format.any(:html, :mobile) do format.any(:html, :mobile) do
#only do it if it is an email address #only do it if it is an email address
if diaspora_id?(search_query) if diaspora_id?(search_query)
@people = Person.where(:diaspora_handle => search_query.downcase) @people = Person.where(diaspora_handle: search_query.downcase, closed_account: false)
if @people.empty? if @people.empty?
Workers::FetchWebfinger.perform_async(search_query) Workers::FetchWebfinger.perform_async(search_query)
@background_query = search_query.downcase @background_query = search_query.downcase
@ -55,7 +55,7 @@ class PeopleController < ApplicationController
def refresh_search def refresh_search
@aspect = :search @aspect = :search
@people = Person.where(:diaspora_handle => search_query.downcase) @people = Person.where(diaspora_handle: search_query.downcase, closed_account: false)
@answer_html = "" @answer_html = ""
unless @people.empty? unless @people.empty?
@hashes = hashes_for_people(@people, @aspects) @hashes = hashes_for_people(@people, @aspects)

View file

@ -159,7 +159,8 @@ class Person < ActiveRecord::Base
).searchable(user) ).searchable(user)
end end
query.where(sql, *tokens) query.where(closed_account: false)
.where(sql, *tokens)
.includes(:profile) .includes(:profile)
.order(["contacts.user_id IS NULL", "profiles.last_name ASC", "profiles.first_name ASC"]) .order(["contacts.user_id IS NULL", "profiles.last_name ASC", "profiles.first_name ASC"])
end end

View file

@ -15,10 +15,19 @@ describe PeopleController, :type => :controller do
describe '#index (search)' do describe '#index (search)' do
before do before do
@eugene = FactoryGirl.create(:person, @eugene = FactoryGirl.create(
:profile => FactoryGirl.build(:profile, :first_name => "Eugene", :last_name => "w")) :person,
@korth = FactoryGirl.create(:person, profile: FactoryGirl.build(:profile, first_name: "Eugene", last_name: "w")
:profile => FactoryGirl.build(:profile, :first_name => "Evan", :last_name => "Korth")) )
@korth = FactoryGirl.create(
:person,
profile: FactoryGirl.build(:profile, first_name: "Evan", last_name: "Korth")
)
@closed = FactoryGirl.create(
:person,
closed_account: true,
profile: FactoryGirl.build(:profile, first_name: "Closed", last_name: "Account")
)
end end
describe 'via json' do describe 'via json' do
@ -36,6 +45,13 @@ describe PeopleController, :type => :controller do
get :index, :q => "Korth", :format => 'json' get :index, :q => "Korth", :format => 'json'
expect(assigns[:hashes]).to be_nil expect(assigns[:hashes]).to be_nil
end end
it "doesn't include closed accounts" do
get :index, q: "Closed", format: "json"
expect(JSON.parse(response.body).size).to eq(0)
get :index, q: @closed.diaspora_handle, format: "json"
expect(JSON.parse(response.body).size).to eq(0)
end
end end
describe 'via html' do describe 'via html' do
@ -64,6 +80,11 @@ describe PeopleController, :type => :controller do
get :index, :q => "Eugene@Example1.ORG" get :index, :q => "Eugene@Example1.ORG"
expect(assigns[:background_query]).to eq("eugene@example1.org") expect(assigns[:background_query]).to eq("eugene@example1.org")
end end
it "doesn't include closed accounts" do
get :index, q: @closed.diaspora_handle
expect(assigns[:people].size).to eq(0)
end
end end
context 'query is not a tag or a diaspora ID' do context 'query is not a tag or a diaspora ID' do
@ -114,6 +135,11 @@ describe PeopleController, :type => :controller do
get :index, :q => "Eug" get :index, :q => "Eug"
expect(assigns[:people]).not_to match_array([eugene2]) expect(assigns[:people]).not_to match_array([eugene2])
end end
it "doesn't include closed accounts" do
get :index, q: "Closed"
expect(assigns[:people].size).to eq(0)
end
end end
end end
end end
@ -516,10 +542,19 @@ describe PeopleController, :type => :controller do
describe '#refresh_search ' do describe '#refresh_search ' do
before(:each)do before(:each)do
@eugene = FactoryGirl.create(:person, @eugene = FactoryGirl.create(
:profile => FactoryGirl.build(:profile, :first_name => "Eugene", :last_name => "w")) :person,
@korth = FactoryGirl.create(:person, profile: FactoryGirl.build(:profile, first_name: "Eugene", last_name: "w")
:profile => FactoryGirl.build(:profile, :first_name => "Evan", :last_name => "Korth")) )
@korth = FactoryGirl.create(
:person,
profile: FactoryGirl.build(:profile, first_name: "Evan", last_name: "Korth")
)
@closed = FactoryGirl.create(
:person,
closed_account: true,
profile: FactoryGirl.build(:profile, first_name: "Closed", last_name: "Account")
)
end end
describe "via json" do describe "via json" do
@ -537,6 +572,11 @@ describe PeopleController, :type => :controller do
get :refresh_search, q: @korth.diaspora_handle get :refresh_search, q: @korth.diaspora_handle
expect(JSON.parse(response.body)["contacts"].size).to eq(1) expect(JSON.parse(response.body)["contacts"].size).to eq(1)
end end
it "doesn't include closed accounts" do
get :refresh_search, q: @closed.diaspora_handle
expect(JSON.parse(response.body)["contacts"]).to be_nil
end
end end
end end

View file

@ -299,6 +299,7 @@ describe Person, :type => :model do
@yevgeniy_dodis = FactoryGirl.build(:person) @yevgeniy_dodis = FactoryGirl.build(:person)
@casey_grippi = FactoryGirl.build(:person) @casey_grippi = FactoryGirl.build(:person)
@invisible_person = FactoryGirl.build(:person) @invisible_person = FactoryGirl.build(:person)
@closed_account = FactoryGirl.build(:person, closed_account: true)
@robert_grimm.profile.first_name = "Robert" @robert_grimm.profile.first_name = "Robert"
@robert_grimm.profile.last_name = "Grimm" @robert_grimm.profile.last_name = "Grimm"
@ -325,6 +326,11 @@ describe Person, :type => :model do
@invisible_person.profile.searchable = false @invisible_person.profile.searchable = false
@invisible_person.profile.save @invisible_person.profile.save
@invisible_person.reload @invisible_person.reload
@closed_account.profile.first_name = "Closed"
@closed_account.profile.last_name = "Account"
@closed_account.profile.save
@closed_account.reload
end end
it 'orders results by last name' do it 'orders results by last name' do
@ -379,6 +385,12 @@ describe Person, :type => :model do
expect(Person.search("Johnson", @user)).to be_empty expect(Person.search("Johnson", @user)).to be_empty
end end
it "doesn't display closed accounts" do
expect(Person.search("Closed", @user)).to be_empty
expect(Person.search("Account", @user)).to be_empty
expect(Person.search(@closed_account.diaspora_handle, @user)).to be_empty
end
it "displays contacts that are not searchable" do it "displays contacts that are not searchable" do
@user.contacts.create(person: @invisible_person, aspects: [@user.aspects.first]) @user.contacts.create(person: @invisible_person, aspects: [@user.aspects.first])
people = Person.search("Johnson", @user) people = Person.search("Johnson", @user)