aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/activity/search.ex8
-rw-r--r--lib/pleroma/user/search.ex25
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex
index f2fdfffe1..9ccedcd13 100644
--- a/lib/pleroma/activity/search.ex
+++ b/lib/pleroma/activity/search.ex
@@ -60,7 +60,13 @@ defmodule Pleroma.Activity.Search do
defp maybe_restrict_local(q, %User{}), do: q
# unauthenticated users can only search local activities
- defp maybe_restrict_local(q, _), do: where(q, local: true)
+ defp maybe_restrict_local(q, _) do
+ if Pleroma.Config.get([:instance, :limit_unauthenticated_to_local_content], true) do
+ where(q, local: true)
+ else
+ q
+ end
+ end
defp maybe_fetch(activities, user, search_query) do
with true <- Regex.match?(~r/https?:/, search_query),
diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex
index d5b2eaa9f..e74143cd0 100644
--- a/lib/pleroma/user/search.ex
+++ b/lib/pleroma/user/search.ex
@@ -14,7 +14,7 @@ defmodule Pleroma.User.Search do
# Strip the beginning @ off if there is a query
query = String.trim_leading(query, "@")
- if match?(%User{}, for_user) and resolve, do: User.get_or_fetch(query)
+ maybe_resolve(resolve, for_user, query)
{:ok, results} =
Repo.transaction(fn ->
@@ -28,6 +28,16 @@ defmodule Pleroma.User.Search do
results
end
+ defp maybe_resolve(true, %User{}, query) do
+ User.get_or_fetch(query)
+ end
+
+ defp maybe_resolve(true, _, query) do
+ unless restrict_local?(), do: User.get_or_fetch(query)
+ end
+
+ defp maybe_resolve(_, _, _), do: :noop
+
defp search_query(query, for_user) do
query
|> union_query()
@@ -39,6 +49,10 @@ defmodule Pleroma.User.Search do
|> maybe_restrict_local(for_user)
end
+ defp restrict_local? do
+ Pleroma.Config.get([:instance, :limit_unauthenticated_to_local_content], true)
+ end
+
defp union_query(query) do
fts_subquery = fts_search_subquery(query)
trigram_subquery = trigram_search_subquery(query)
@@ -52,7 +66,14 @@ defmodule Pleroma.User.Search do
# unauthenticated users can only search local activities
defp maybe_restrict_local(q, %User{}), do: q
- defp maybe_restrict_local(q, _), do: where(q, [u], u.local == true)
+
+ defp maybe_restrict_local(q, _) do
+ if restrict_local?() do
+ where(q, [u], u.local == true)
+ else
+ q
+ end
+ end
defp boost_search_rank_query(query, nil), do: query