mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-05-24 04:28:04 +00:00
Do not translate non-public statuses
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
90f590788c
commit
aa429f6e6a
|
@ -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")
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue