summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--config/config.exs2
-rw-r--r--docs/config.md4
-rw-r--r--lib/pleroma/activity/search.ex20
-rw-r--r--lib/pleroma/user/search.ex41
-rw-r--r--lib/pleroma/web/rich_media/helpers.ex2
-rw-r--r--mix.exs2
-rw-r--r--mix.lock2
-rw-r--r--test/activity_test.exs13
-rw-r--r--test/user_test.exs18
10 files changed, 63 insertions, 43 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d2900cc97..7ecdfe939 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,7 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Configuration: `notify_email` option
- Configuration: Media proxy `whitelist` option
- Configuration: `report_uri` option
-- Configuration: `limit_unauthenticated_to_local_content` option
+- Configuration: `limit_to_local_content` option
- Pleroma API: User subscriptions
- Pleroma API: Healthcheck endpoint
- Pleroma API: `/api/v1/pleroma/mascot` per-user frontend mascot configuration endpoints
diff --git a/config/config.exs b/config/config.exs
index b73541213..f866e8d2b 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -245,7 +245,7 @@ config :pleroma, :instance,
healthcheck: false,
remote_post_retention_days: 90,
skip_thread_containment: true,
- limit_unauthenticated_to_local_content: true
+ limit_to_local_content: :unauthenticated
config :pleroma, :markup,
# XXX - unfortunately, inline images must be enabled by default right now, because
diff --git a/docs/config.md b/docs/config.md
index b62b80490..2b0f5726b 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -86,6 +86,7 @@ config :pleroma, Pleroma.Emails.Mailer,
* `Pleroma.Web.ActivityPub.MRF.NoOpPolicy`: Doesn’t modify activities (default)
* `Pleroma.Web.ActivityPub.MRF.DropPolicy`: Drops all activities. It generally doesn’t makes sense to use in production
* `Pleroma.Web.ActivityPub.MRF.SimplePolicy`: Restrict the visibility of activities from certains instances (See ``:mrf_simple`` section)
+ * `Pleroma.Web.ActivityPub.MRF.TagPolicy`: Applies policies to individual users based on tags, which can be set using pleroma-fe/admin-fe/any other app that supports Pleroma Admin API. For example it allows marking posts from individual users nsfw (sensitive)
* `Pleroma.Web.ActivityPub.MRF.SubchainPolicy`: Selectively runs other MRF policies when messages match (see ``:mrf_subchain`` section)
* `Pleroma.Web.ActivityPub.MRF.RejectNonPublic`: Drops posts with non-public visibility settings (See ``:mrf_rejectnonpublic`` section)
* `Pleroma.Web.ActivityPub.MRF.EnsureRePrepended`: Rewrites posts to ensure that replies to posts with subjects do not have an identical subject and instead begin with re:.
@@ -112,7 +113,8 @@ config :pleroma, Pleroma.Emails.Mailer,
* `healthcheck`: If set to true, system data will be shown on ``/api/pleroma/healthcheck``.
* `remote_post_retention_days`: The default amount of days to retain remote posts when pruning the database.
* `skip_thread_containment`: Skip filter out broken threads. The default is `false`.
-* `limit_unauthenticated_to_local_content`: Limit unauthenticated users to search for local statutes and users only. The default is `true`.
+* `limit_to_local_content`: Limit unauthenticated users to search for local statutes and users only. Possible values: `:unauthenticated`, `:all` and `false`. The default is `:unauthenticated`.
+
## :logger
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog, and `Quack.Logger` to log to Slack
diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex
index 9ccedcd13..0aa2aab23 100644
--- a/lib/pleroma/activity/search.ex
+++ b/lib/pleroma/activity/search.ex
@@ -39,8 +39,7 @@ defmodule Pleroma.Activity.Search do
"to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)",
o.data,
^search_query
- ),
- order_by: [desc: :id]
+ )
)
end
@@ -56,18 +55,19 @@ defmodule Pleroma.Activity.Search do
)
end
- # users can search everything
- defp maybe_restrict_local(q, %User{}), do: q
+ defp maybe_restrict_local(q, user) do
+ limit = Pleroma.Config.get([:instance, :limit_to_local_content], :unauthenticated)
- # unauthenticated users can only search local activities
- defp maybe_restrict_local(q, _) do
- if Pleroma.Config.get([:instance, :limit_unauthenticated_to_local_content], true) do
- where(q, local: true)
- else
- q
+ case {limit, user} do
+ {:all, _} -> restrict_local(q)
+ {:unauthenticated, %User{}} -> q
+ {:unauthenticated, _} -> restrict_local(q)
+ {false, _} -> q
end
end
+ defp restrict_local(q), do: where(q, local: true)
+
defp maybe_fetch(activities, user, search_query) do
with true <- Regex.match?(~r/https?:/, search_query),
{:ok, object} <- Fetcher.fetch_object_from_id(search_query),
diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex
index add6a0bbf..f88dffa7b 100644
--- a/lib/pleroma/user/search.ex
+++ b/lib/pleroma/user/search.ex
@@ -28,16 +28,6 @@ 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()
@@ -49,10 +39,6 @@ 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)
@@ -64,17 +50,30 @@ defmodule Pleroma.User.Search do
from(s in subquery(q), order_by: s.search_type, distinct: s.id)
end
- # unauthenticated users can only search local activities
- defp maybe_restrict_local(q, %User{}), do: q
+ defp maybe_resolve(true, user, query) do
+ case {limit(), user} do
+ {:all, _} -> :noop
+ {:unauthenticated, %User{}} -> User.get_or_fetch(query)
+ {:unauthenticated, _} -> :noop
+ {false, _} -> User.get_or_fetch(query)
+ end
+ end
- defp maybe_restrict_local(q, _) do
- if restrict_local?() do
- where(q, [u], u.local == true)
- else
- q
+ defp maybe_resolve(_, _, _), do: :noop
+
+ defp maybe_restrict_local(q, user) do
+ case {limit(), user} do
+ {:all, _} -> restrict_local(q)
+ {:unauthenticated, %User{}} -> q
+ {:unauthenticated, _} -> restrict_local(q)
+ {false, _} -> q
end
end
+ defp limit, do: Pleroma.Config.get([:instance, :limit_to_local_content], :unauthenticated)
+
+ defp restrict_local(q), do: where(q, [u], u.local == true)
+
defp boost_search_rank_query(query, nil), do: query
defp boost_search_rank_query(query, for_user) do
diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex
index 9bc8f2559..f377125d7 100644
--- a/lib/pleroma/web/rich_media/helpers.ex
+++ b/lib/pleroma/web/rich_media/helpers.ex
@@ -9,7 +9,7 @@ defmodule Pleroma.Web.RichMedia.Helpers do
alias Pleroma.Web.RichMedia.Parser
defp validate_page_url(page_url) when is_binary(page_url) do
- if AutoLinker.Parser.is_url?(page_url, true) do
+ if AutoLinker.Parser.url?(page_url, true) do
URI.parse(page_url) |> validate_page_url
else
:error
diff --git a/mix.exs b/mix.exs
index bfa9bf18b..db7a30f99 100644
--- a/mix.exs
+++ b/mix.exs
@@ -126,7 +126,7 @@ defmodule Pleroma.Mixfile do
{:ueberauth, "~> 0.4"},
{:auto_linker,
git: "https://git.pleroma.social/pleroma/auto_linker.git",
- ref: "c00c4e75b35367fa42c95ffd9b8c455bf9995829"},
+ ref: "e2385402bcd24fc659fee83b3eb8863b0528ad42"},
{:http_signatures,
git: "https://git.pleroma.social/pleroma/http_signatures.git",
ref: "9789401987096ead65646b52b5a2ca6bf52fc531"},
diff --git a/mix.lock b/mix.lock
index de9d811e6..90cdf41f7 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,6 +1,6 @@
%{
"accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm"},
- "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "c00c4e75b35367fa42c95ffd9b8c455bf9995829", [ref: "c00c4e75b35367fa42c95ffd9b8c455bf9995829"]},
+ "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "e2385402bcd24fc659fee83b3eb8863b0528ad42", [ref: "e2385402bcd24fc659fee83b3eb8863b0528ad42"]},
"base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"},
"bbcode": {:hex, :bbcode, "0.1.0", "400e618b640b635261611d7fb7f79d104917fc5b084aae371ab6b08477cb035b", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"},
diff --git a/test/activity_test.exs b/test/activity_test.exs
index e56e39096..7ba4363c8 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -139,18 +139,25 @@ defmodule Pleroma.ActivityTest do
assert [^local_activity] = Activity.search(nil, "find me")
end
- test "find all statuses for unauthenticated users when `limit_unauthenticated_to_local_content` is `false`",
+ test "find only local statuses for unauthenticated users when `limit_to_local_content` is `:all`",
+ %{local_activity: local_activity} do
+ Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+ assert [^local_activity] = Activity.search(nil, "find me")
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ end
+
+ test "find all statuses for unauthenticated users when `limit_to_local_content` is `false`",
%{
local_activity: local_activity,
remote_activity: remote_activity
} do
- Pleroma.Config.put([:instance, :limit_unauthenticated_to_local_content], false)
+ Pleroma.Config.put([:instance, :limit_to_local_content], false)
activities = Enum.sort_by(Activity.search(nil, "find me"), & &1.id)
assert [^local_activity, ^remote_activity] = activities
- Pleroma.Config.put([:instance, :limit_unauthenticated_to_local_content], true)
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
end
end
end
diff --git a/test/user_test.exs b/test/user_test.exs
index 8dd672173..473f545ff 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1099,8 +1099,20 @@ defmodule Pleroma.UserTest do
assert [%{id: ^id}] = User.search("lain")
end
- test "find all users for unauthenticated users when `limit_unauthenticated_to_local_content` is `false`" do
- Pleroma.Config.put([:instance, :limit_unauthenticated_to_local_content], false)
+ test "find only local users for authenticated users when `limit_to_local_content` is `:all`" do
+ Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+
+ %{id: id} = insert(:user, %{name: "lain"})
+ insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
+ insert(:user, %{nickname: "lain@pleroma.soykaf.com", local: false})
+
+ assert [%{id: ^id}] = User.search("lain")
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ end
+
+ test "find all users for unauthenticated users when `limit_to_local_content` is `false`" do
+ Pleroma.Config.put([:instance, :limit_to_local_content], false)
u1 = insert(:user, %{name: "lain"})
u2 = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social", local: false})
@@ -1114,7 +1126,7 @@ defmodule Pleroma.UserTest do
assert [u1.id, u2.id, u3.id] == results
- Pleroma.Config.put([:instance, :limit_unauthenticated_to_local_content], true)
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
end
test "finds a user whose name is nil" do