commit: aa429f6e6a059e58af2550d87f8272dea92acc9e
parent 90f590788cffd154f9d2b40e5e644ad533883195
Author: marcin mikołajczak <git@mkljczk.pl>
Date: Sun, 30 Oct 2022 21:57:05 +0100
Do not translate non-public statuses
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
Diffstat:
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex
@@ -560,6 +560,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
@doc "POST /api/v1/statuses/:id/translate"
def translate(%{body_params: params, assigns: %{user: user}} = conn, %{id: status_id}) do
with %Activity{object: object} <- Activity.get_by_id_with_object(status_id),
+ {:visibility, visibility} when visibility in ["public", "unlisted"] <-
+ {:visibility, Visibility.get_visibility(object)},
{:language, language} when is_binary(language) <-
{:language, Map.get(params, :target_language) || user.language},
{:ok, result} <-
@@ -573,6 +575,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
{:language, nil} ->
render_error(conn, :bad_request, "Language not specified")
+ {:visibility, _} ->
+ render_error(conn, :not_found, "Record not found")
+
{:error, :not_found} ->
render_error(conn, :not_found, "Translation service not configured")
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -2571,7 +2571,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> post("/api/v1/statuses/#{activity.id}/translate")
|> json_response_and_validate_schema(200)
- assert response == %{"content" => "!ćśezC", "detected_source_language" => "pl", "provider" => "TranslationMock"}
+ assert response == %{
+ "content" => "!ćśezC",
+ "detected_source_language" => "pl",
+ "provider" => "TranslationMock"
+ }
end
test "it returns an error if no target language provided" do
@@ -2589,5 +2593,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> post("/api/v1/statuses/#{activity.id}/translate")
|> json_response_and_validate_schema(400)
end
+
+ test "it doesn't translate non-public statuses" do
+ %{conn: conn, user: user} = oauth_access(["read:statuses"])
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ status: "Cześć!",
+ visibility: "private",
+ language: "pl"
+ })
+
+ response =
+ conn
+ |> post("/api/v1/statuses/#{activity.id}/translate")
+ |> json_response_and_validate_schema(404)
+ end
end
end