summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.d/notification-spex.skip0
-rw-r--r--changelog.d/rich_media_config.skip0
-rw-r--r--lib/pleroma/web/api_spec/cast_and_validate.ex6
-rw-r--r--lib/pleroma/web/api_spec/operations/notification_operation.ex8
-rw-r--r--lib/pleroma/web/rich_media/card.ex25
-rw-r--r--lib/pleroma/web/rich_media/parser.ex6
-rw-r--r--test/pleroma/web/rich_media/parser_test.exs8
7 files changed, 41 insertions, 12 deletions
diff --git a/changelog.d/notification-spex.skip b/changelog.d/notification-spex.skip
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/changelog.d/notification-spex.skip
diff --git a/changelog.d/rich_media_config.skip b/changelog.d/rich_media_config.skip
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/changelog.d/rich_media_config.skip
diff --git a/lib/pleroma/web/api_spec/cast_and_validate.ex b/lib/pleroma/web/api_spec/cast_and_validate.ex
index f3e8e093e..eb487fce7 100644
--- a/lib/pleroma/web/api_spec/cast_and_validate.ex
+++ b/lib/pleroma/web/api_spec/cast_and_validate.ex
@@ -18,6 +18,8 @@ defmodule Pleroma.Web.ApiSpec.CastAndValidate do
alias OpenApiSpex.Plug.PutApiSpec
alias Plug.Conn
+ require Logger
+
@impl Plug
def init(opts) do
opts
@@ -51,6 +53,10 @@ defmodule Pleroma.Web.ApiSpec.CastAndValidate do
conn
{:error, reason} ->
+ Logger.error(
+ "Strict ApiSpec: request denied to #{conn.path_info} with params #{inspect(conn.params)}"
+ )
+
opts = render_error.init(reason)
conn
diff --git a/lib/pleroma/web/api_spec/operations/notification_operation.ex b/lib/pleroma/web/api_spec/operations/notification_operation.ex
index a79eb8f74..2dc0f66df 100644
--- a/lib/pleroma/web/api_spec/operations/notification_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/notification_operation.ex
@@ -203,7 +203,10 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
"move",
"follow_request",
"poll",
- "status"
+ "status",
+ "update",
+ "admin.sign_up",
+ "admin.report"
],
description: """
The type of event that resulted in the notification.
@@ -218,6 +221,9 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
- `pleroma:chat_mention` - Someone mentioned you in a chat message
- `pleroma:report` - Someone was reported
- `status` - Someone you are subscribed to created a status
+ - `update` - A status you boosted has been edited
+ - `admin.sign_up` - Someone signed up (optionally sent to admins)
+ - `admin.report` - A new report has been filed
"""
}
end
diff --git a/lib/pleroma/web/rich_media/card.ex b/lib/pleroma/web/rich_media/card.ex
index 36a1ae44a..040066f36 100644
--- a/lib/pleroma/web/rich_media/card.ex
+++ b/lib/pleroma/web/rich_media/card.ex
@@ -77,19 +77,23 @@ defmodule Pleroma.Web.RichMedia.Card do
@spec get_or_backfill_by_url(String.t(), map()) :: t() | nil
def get_or_backfill_by_url(url, backfill_opts \\ %{}) do
- case get_by_url(url) do
- %__MODULE__{} = card ->
- card
+ if @config_impl.get([:rich_media, :enabled]) do
+ case get_by_url(url) do
+ %__MODULE__{} = card ->
+ card
- nil ->
- backfill_opts = Map.put(backfill_opts, :url, url)
+ nil ->
+ backfill_opts = Map.put(backfill_opts, :url, url)
- Backfill.start(backfill_opts)
+ Backfill.start(backfill_opts)
- nil
+ nil
- :error ->
- nil
+ :error ->
+ nil
+ end
+ else
+ nil
end
end
@@ -104,7 +108,8 @@ defmodule Pleroma.Web.RichMedia.Card do
@spec get_by_activity(Activity.t()) :: t() | nil | :error
# Fake/Draft activity
def get_by_activity(%Activity{id: "pleroma:fakeid"} = activity) do
- with %Object{} = object <- Object.normalize(activity, fetch: false),
+ with {_, true} <- {:config, @config_impl.get([:rich_media, :enabled])},
+ %Object{} = object <- Object.normalize(activity, fetch: false),
url when not is_nil(url) <- HTML.extract_first_external_url_from_object(object) do
case get_by_url(url) do
# Cache hit
diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex
index 37cf29029..7f6b5d388 100644
--- a/lib/pleroma/web/rich_media/parser.ex
+++ b/lib/pleroma/web/rich_media/parser.ex
@@ -15,10 +15,14 @@ defmodule Pleroma.Web.RichMedia.Parser do
@spec parse(String.t()) :: {:ok, map()} | {:error, any()}
def parse(url) do
- with :ok <- validate_page_url(url),
+ with {_, true} <- {:config, @config_impl.get([:rich_media, :enabled])},
+ :ok <- validate_page_url(url),
{:ok, data} <- parse_url(url) do
data = Map.put(data, "url", url)
{:ok, data}
+ else
+ {:config, _} -> {:error, :rich_media_disabled}
+ e -> e
end
end
diff --git a/test/pleroma/web/rich_media/parser_test.exs b/test/pleroma/web/rich_media/parser_test.exs
index 3fcb5c808..a5f2563a2 100644
--- a/test/pleroma/web/rich_media/parser_test.exs
+++ b/test/pleroma/web/rich_media/parser_test.exs
@@ -13,6 +13,8 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
end
+ setup_all do: clear_config([:rich_media, :enabled], true)
+
test "returns error when no metadata present" do
assert {:error, _} = Parser.parse("https://example.com/empty")
end
@@ -127,4 +129,10 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
assert :error == Parser.parse(url)
end)
end
+
+ test "returns error when disabled" do
+ clear_config([:rich_media, :enabled], false)
+
+ assert match?({:error, :rich_media_disabled}, Parser.parse("https://example.com/ogp"))
+ end
end