logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: de9194893e811eaa5e14e07ae208da84006b6f38
parent b389b85d7760d9c275b2584e0e99bff4f0265222
Author: marcin mikołajczak <git@mkljczk.pl>
Date:   Sat,  3 Aug 2024 18:28:43 +0200

Support `id` param in `GET /api/v1/statuses`

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>

Diffstat:

Achangelog.d/get-statuses-param.change2++
Mlib/pleroma/web/api_spec/operations/status_operation.ex8+++++++-
Mlib/pleroma/web/mastodon_api/controllers/status_controller.ex3++-
Mtest/pleroma/web/mastodon_api/controllers/status_controller_test.exs28+++++++++++++++++++---------
4 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/changelog.d/get-statuses-param.change b/changelog.d/get-statuses-param.change @@ -0,0 +1 @@ +Support `id` param in `GET /api/v1/statuses` +\ No newline at end of file diff --git a/lib/pleroma/web/api_spec/operations/status_operation.ex b/lib/pleroma/web/api_spec/operations/status_operation.ex @@ -31,12 +31,18 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do security: [%{"oAuth" => ["read:statuses"]}], parameters: [ Operation.parameter( - :ids, + :id, :query, %Schema{type: :array, items: FlakeID}, "Array of status IDs" ), Operation.parameter( + :ids, + :query, + %Schema{type: :array, items: FlakeID}, + "Deprecated, use `id` instead" + ), + Operation.parameter( :with_muted, :query, BooleanLike.schema(), diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -111,10 +111,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do `ids` query param is required """ def index( - %{assigns: %{user: user}, private: %{open_api_spex: %{params: %{ids: ids} = params}}} = + %{assigns: %{user: user}, private: %{open_api_spex: %{params: params}}} = conn, _ ) do + ids = Map.get(params, :id, Map.get(params, :ids)) limit = 100 activities = diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -922,13 +922,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do %{id: id1} = insert(:note_activity) %{id: id2} = insert(:note_activity) - query_string = "ids[]=#{id1}&ids[]=#{id2}" + query_string = "id[]=#{id1}&id[]=#{id2}" conn = get(conn, "/api/v1/statuses/?#{query_string}") assert [%{"id" => ^id1}, %{"id" => ^id2}] = Enum.sort_by(json_response_and_validate_schema(conn, :ok), & &1["id"]) end + test "get statuses by IDs falls back to ids[]" do + %{conn: conn} = oauth_access(["read:statuses"]) + %{id: id} = insert(:note_activity) + + query_string = "ids[]=#{id}" + conn = get(conn, "/api/v1/statuses/?#{query_string}") + + assert [%{"id" => ^id}] = json_response_and_validate_schema(conn, 200) + end + describe "getting statuses by ids with restricted unauthenticated for local and remote" do setup do: local_and_remote_activities() @@ -937,7 +947,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true) test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do - res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") + res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}") assert json_response_and_validate_schema(res_conn, 200) == [] end @@ -945,7 +955,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do test "if user is authenticated", %{local: local, remote: remote} do %{conn: conn} = oauth_access(["read"]) - res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") + res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}") assert length(json_response_and_validate_schema(res_conn, 200)) == 2 end @@ -957,7 +967,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do setup do: clear_config([:restrict_unauthenticated, :activities, :local], true) test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do - res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") + res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}") remote_id = remote.id assert [%{"id" => ^remote_id}] = json_response_and_validate_schema(res_conn, 200) @@ -966,7 +976,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do test "if user is authenticated", %{local: local, remote: remote} do %{conn: conn} = oauth_access(["read"]) - res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") + res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}") assert length(json_response_and_validate_schema(res_conn, 200)) == 2 end @@ -978,7 +988,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true) test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do - res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") + res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}") local_id = local.id assert [%{"id" => ^local_id}] = json_response_and_validate_schema(res_conn, 200) @@ -987,7 +997,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do test "if user is authenticated", %{local: local, remote: remote} do %{conn: conn} = oauth_access(["read"]) - res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}") + res_conn = get(conn, "/api/v1/statuses?id[]=#{local.id}&id[]=#{remote.id}") assert length(json_response_and_validate_schema(res_conn, 200)) == 2 end @@ -2241,7 +2251,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do result = conn - |> get("/api/v1/statuses/?ids[]=#{activity.id}") + |> get("/api/v1/statuses/?id[]=#{activity.id}") |> json_response_and_validate_schema(200) assert [ @@ -2254,7 +2264,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do result = conn - |> get("/api/v1/statuses/?ids[]=#{activity.id}&with_muted=true") + |> get("/api/v1/statuses/?id[]=#{activity.id}&with_muted=true") |> json_response_and_validate_schema(200) assert [