User: search: exclude deactivated users from user search
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending
This way we don't pollute search results with deactivated and deleted users
This commit is contained in:
parent
00f840fd44
commit
77596a3021
2 changed files with 13 additions and 0 deletions
|
@ -94,6 +94,7 @@ defp search_query(query_string, for_user, following, top_user_ids) do
|
||||||
|> subquery()
|
|> subquery()
|
||||||
|> order_by(desc: :search_rank)
|
|> order_by(desc: :search_rank)
|
||||||
|> maybe_restrict_local(for_user)
|
|> maybe_restrict_local(for_user)
|
||||||
|
|> filter_deactivated_users()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp select_top_users(query, top_user_ids) do
|
defp select_top_users(query, top_user_ids) do
|
||||||
|
@ -166,6 +167,10 @@ defp filter_internal_users(query) do
|
||||||
from(q in query, where: q.actor_type != "Application")
|
from(q in query, where: q.actor_type != "Application")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp filter_deactivated_users(query) do
|
||||||
|
from(q in query, where: q.is_active == true)
|
||||||
|
end
|
||||||
|
|
||||||
defp filter_blocked_user(query, %User{} = blocker) do
|
defp filter_blocked_user(query, %User{} = blocker) do
|
||||||
query
|
query
|
||||||
|> join(:left, [u], b in Pleroma.UserRelationship,
|
|> join(:left, [u], b in Pleroma.UserRelationship,
|
||||||
|
|
|
@ -65,6 +65,14 @@ test "excludes invisible users from results" do
|
||||||
assert found_user.id == user.id
|
assert found_user.id == user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "excludes deactivated users from results" do
|
||||||
|
user = insert(:user, %{nickname: "john t1000"})
|
||||||
|
insert(:user, %{is_active: false, nickname: "john t800"})
|
||||||
|
|
||||||
|
[found_user] = User.search("john")
|
||||||
|
assert found_user.id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
# Note: as in Mastodon, `is_discoverable` doesn't anyhow relate to user searchability
|
# Note: as in Mastodon, `is_discoverable` doesn't anyhow relate to user searchability
|
||||||
test "includes non-discoverable users in results" do
|
test "includes non-discoverable users in results" do
|
||||||
insert(:user, %{nickname: "john 3000", is_discoverable: false})
|
insert(:user, %{nickname: "john 3000", is_discoverable: false})
|
||||||
|
|
Loading…
Reference in a new issue