From b53abd9d79eff1d7a650954a9585a145105b6e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 26 Apr 2024 00:00:30 +0200 Subject: [PATCH] changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- changelog.d/translate-posts.add | 1 + .../controllers/instance_controller.ex | 2 +- .../controllers/status_controller.ex | 8 +++++++- .../web/mastodon_api/views/instance_view.ex | 18 +++++++++--------- .../controllers/status_controller_test.exs | 18 ++++++++---------- 5 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 changelog.d/translate-posts.add diff --git a/changelog.d/translate-posts.add b/changelog.d/translate-posts.add new file mode 100644 index 000000000..e7a9317a1 --- /dev/null +++ b/changelog.d/translate-posts.add @@ -0,0 +1 @@ +Support translation providers (DeepL, LibreTranslate) \ No newline at end of file diff --git a/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex b/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex index bce64cf6e..ed015d574 100644 --- a/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex @@ -24,7 +24,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceController do @doc "GET /api/v1/instance/peers" def peers(conn, _params) do json(conn, Pleroma.Stats.get_peers()) -end + end @doc "GET /api/v1/instance/translation_languages" def translation_languages(conn, _params) do diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 733f33e13..ad1e78c30 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -558,7 +558,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do end @doc "POST /api/v1/statuses/:id/translate" - def translate(%{body_params: params, assigns: %{user: user}} = conn, %{id: status_id}) do + def translate( + %{ + assigns: %{user: user}, + private: %{open_api_spex: %{body_params: params, params: %{id: status_id}}} + } = conn, + _ + ) 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)}, diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 096ed00ad..e093b1a2f 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -75,15 +75,6 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do }) end - defp common_information(instance) do - %{ - title: Keyword.get(instance, :name), - version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})", - languages: Keyword.get(instance, :languages, ["en"]), - rules: [] - } - end - def render("translation_languages.json", _) do with true <- Pleroma.Language.Translation.configured?(), {:ok, languages} <- Pleroma.Language.Translation.languages_matrix() do @@ -93,6 +84,15 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do end end + defp common_information(instance) do + %{ + title: Keyword.get(instance, :name), + version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})", + languages: Keyword.get(instance, :languages, ["en"]), + rules: [] + } + end + def features do [ "pleroma_api", diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index f05f4191d..2a64cac5f 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -2556,7 +2556,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do test "it translates a status to user language" do user = insert(:user, language: "fr") - %{conn: conn, user: user} = oauth_access(["read:statuses"], user: user) + %{conn: conn} = oauth_access(["read:statuses"], user: user) another_user = insert(:user) {:ok, activity} = @@ -2579,7 +2579,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do end test "it returns an error if no target language provided" do - %{conn: conn, user: user} = oauth_access(["read:statuses"]) + %{conn: conn} = oauth_access(["read:statuses"]) another_user = insert(:user) {:ok, activity} = @@ -2588,10 +2588,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do language: "pl" }) - response = - conn - |> post("/api/v1/statuses/#{activity.id}/translate") - |> json_response_and_validate_schema(400) + assert conn + |> post("/api/v1/statuses/#{activity.id}/translate") + |> json_response_and_validate_schema(400) end test "it doesn't translate non-public statuses" do @@ -2604,10 +2603,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do language: "pl" }) - response = - conn - |> post("/api/v1/statuses/#{activity.id}/translate") - |> json_response_and_validate_schema(404) + assert conn + |> post("/api/v1/statuses/#{activity.id}/translate") + |> json_response_and_validate_schema(404) end end end