do not fetch if limit_to_local_content is enabled
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending
Prior to this change, anyone, authenticated or not, could submit a search query for an activity by URL, and cause the fetcher to go fetch it. That shouldn't happen if `limit_to_local_content` is set to `:all` or if it's set to `:unauthenticated` and the query came from an unauthenticated source.
This commit is contained in:
parent
8c956bc671
commit
97037c0b53
1 changed files with 14 additions and 6 deletions
|
@ -132,21 +132,29 @@ defp query_with(q, :rum, search_query, :websearch) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_restrict_local(q, user) do
|
def should_restrict_local(user) do
|
||||||
limit = Pleroma.Config.get([:instance, :limit_to_local_content], :unauthenticated)
|
limit = Pleroma.Config.get([:instance, :limit_to_local_content], :unauthenticated)
|
||||||
|
|
||||||
case {limit, user} do
|
case {limit, user} do
|
||||||
{:all, _} -> restrict_local(q)
|
{:all, _} -> true
|
||||||
{:unauthenticated, %User{}} -> q
|
{:unauthenticated, %User{}} -> false
|
||||||
{:unauthenticated, _} -> restrict_local(q)
|
{:unauthenticated, _} -> true
|
||||||
{false, _} -> q
|
{false, _} -> false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def maybe_restrict_local(q, user) do
|
||||||
|
case should_restrict_local(user) do
|
||||||
|
true -> restrict_local(q)
|
||||||
|
false -> q
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp restrict_local(q), do: where(q, local: true)
|
defp restrict_local(q), do: where(q, local: true)
|
||||||
|
|
||||||
def maybe_fetch(activities, user, search_query) do
|
def maybe_fetch(activities, user, search_query) do
|
||||||
with true <- Regex.match?(~r/https?:/, search_query),
|
with false <- should_restrict_local(user),
|
||||||
|
true <- Regex.match?(~r/https?:/, search_query),
|
||||||
{:ok, object} <- Fetcher.fetch_object_from_id(search_query),
|
{:ok, object} <- Fetcher.fetch_object_from_id(search_query),
|
||||||
%Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]),
|
%Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]),
|
||||||
true <- Visibility.visible_for_user?(activity, user) do
|
true <- Visibility.visible_for_user?(activity, user) do
|
||||||
|
|
Loading…
Reference in a new issue