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:
parent
44b7706a2b
commit
8a2995f719
|
@ -26,6 +26,7 @@ class UserSearch
|
||||||
|
|
||||||
def scoped_users
|
def scoped_users
|
||||||
users = User.where(active: true)
|
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.where(staged: false) unless @include_staged_users
|
||||||
users = users.not_suspended unless @searching_user&.staff?
|
users = users.not_suspended unless @searching_user&.staff?
|
||||||
|
|
||||||
|
|
|
@ -226,6 +226,18 @@ RSpec.describe UserSearch do
|
||||||
expect(results).to be_blank
|
expect(results).to be_blank
|
||||||
end
|
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
|
it "prioritises exact matches" do
|
||||||
results = search_for("mrB")
|
results = search_for("mrB")
|
||||||
expect(results).to eq [mr_b, mr_brown, mr_blue].map(&:username)
|
expect(results).to eq [mr_b, mr_brown, mr_blue].map(&:username)
|
||||||
|
|
Loading…
Reference in New Issue