Skip to content
Extraits de code Groupes Projets
Valider 495303d9 rédigé par Emelia Smith's avatar Emelia Smith Validation de Eugen Rochko
Parcourir les fichiers

Prevent suspended accounts from appearing in AccountSearchService (#7246)

parent 53b1d888
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -117,6 +117,7 @@ class Account < ApplicationRecord ...@@ -117,6 +117,7 @@ class Account < ApplicationRecord
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) } scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
scope :silenced, -> { where(silenced: true) } scope :silenced, -> { where(silenced: true) }
scope :suspended, -> { where(suspended: true) } scope :suspended, -> { where(suspended: true) }
scope :without_suspended, -> { where(suspended: false) }
scope :recent, -> { reorder(id: :desc) } scope :recent, -> { reorder(id: :desc) }
scope :alphabetic, -> { order(domain: :asc, username: :asc) } scope :alphabetic, -> { order(domain: :asc, username: :asc) }
scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') } scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') }
......
...@@ -65,9 +65,9 @@ class AccountSearchService < BaseService ...@@ -65,9 +65,9 @@ class AccountSearchService < BaseService
def exact_match def exact_match
@_exact_match ||= begin @_exact_match ||= begin
if domain_is_local? if domain_is_local?
search_from.find_local(query_username) search_from.without_suspended.find_local(query_username)
else else
search_from.find_remote(query_username, query_domain) search_from.without_suspended.find_remote(query_username, query_domain)
end end
end end
end end
......
...@@ -137,5 +137,24 @@ describe AccountSearchService do ...@@ -137,5 +137,24 @@ describe AccountSearchService do
expect(service).not_to have_received(:call) expect(service).not_to have_received(:call)
end end
end end
describe 'should not include suspended accounts' do
it 'returns the fuzzy match first, and does not return suspended exacts' do
partial = Fabricate(:account, username: 'exactness')
exact = Fabricate(:account, username: 'exact', suspended: true)
results = subject.call('exact', 10)
expect(results.size).to eq 1
expect(results).to eq [partial]
end
it "does not return suspended remote accounts" do
remote = Fabricate(:account, username: 'a', domain: 'remote', display_name: 'e', suspended: true)
results = subject.call('a@example.com', 2)
expect(results.size).to eq 0
expect(results).to eq []
end
end
end end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter