FIX: only show approved users in search_user results when site setting enabled (#20493)

Returns only approved users when using @ in composer (if must_approve_users site setting enabled).
This commit is contained in:
David Battersby 2023-03-01 12:23:29 +08:00 committed by GitHub
parent 44b7706a2b
commit 8a2995f719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -26,6 +26,7 @@ class UserSearch
def scoped_users
users = User.where(active: true)
users = users.where(approved: true) if SiteSetting.must_approve_users?
users = users.where(staged: false) unless @include_staged_users
users = users.not_suspended unless @searching_user&.staff?

View File

@ -226,6 +226,18 @@ RSpec.describe UserSearch do
expect(results).to be_blank
end
it "does not show unapproved users when must_approve_users enabled" do
SiteSetting.must_approve_users = true
unapproved = Fabricate(:user, username: "mrunapproved", active: true, approved: false)
approved = Fabricate(:user, username: "mrapproved", active: true, approved: true)
users = search_for(unapproved.username)
expect(users).to be_blank
users = search_for(approved.username)
expect(users).not_to be_blank
end
it "prioritises exact matches" do
results = search_for("mrB")
expect(results).to eq [mr_b, mr_brown, mr_blue].map(&:username)