mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Merge branch 'get-statuses-param' into 'develop'
Support `id` param in `GET /api/v1/statuses` See merge request pleroma/pleroma!4204
This commit is contained in:
commit
9cf684d661
4 changed files with 29 additions and 11 deletions
1
changelog.d/get-statuses-param.change
Normal file
1
changelog.d/get-statuses-param.change
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Support `id` param in `GET /api/v1/statuses`
|
|
@ -31,11 +31,17 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
||||||
security: [%{"oAuth" => ["read:statuses"]}],
|
security: [%{"oAuth" => ["read:statuses"]}],
|
||||||
parameters: [
|
parameters: [
|
||||||
Operation.parameter(
|
Operation.parameter(
|
||||||
:ids,
|
:id,
|
||||||
:query,
|
:query,
|
||||||
%Schema{type: :array, items: FlakeID},
|
%Schema{type: :array, items: FlakeID},
|
||||||
"Array of status IDs"
|
"Array of status IDs"
|
||||||
),
|
),
|
||||||
|
Operation.parameter(
|
||||||
|
:ids,
|
||||||
|
:query,
|
||||||
|
%Schema{type: :array, items: FlakeID},
|
||||||
|
"Deprecated, use `id` instead"
|
||||||
|
),
|
||||||
Operation.parameter(
|
Operation.parameter(
|
||||||
:with_muted,
|
:with_muted,
|
||||||
:query,
|
:query,
|
||||||
|
|
|
@ -111,10 +111,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
|
||||||
`ids` query param is required
|
`ids` query param is required
|
||||||
"""
|
"""
|
||||||
def index(
|
def index(
|
||||||
%{assigns: %{user: user}, private: %{open_api_spex: %{params: %{ids: ids} = params}}} =
|
%{assigns: %{user: user}, private: %{open_api_spex: %{params: params}}} =
|
||||||
conn,
|
conn,
|
||||||
_
|
_
|
||||||
) do
|
) do
|
||||||
|
ids = Map.get(params, :id, Map.get(params, :ids))
|
||||||
limit = 100
|
limit = 100
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
|
|
|
@ -922,13 +922,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
%{id: id1} = insert(:note_activity)
|
%{id: id1} = insert(:note_activity)
|
||||||
%{id: id2} = 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}")
|
conn = get(conn, "/api/v1/statuses/?#{query_string}")
|
||||||
|
|
||||||
assert [%{"id" => ^id1}, %{"id" => ^id2}] =
|
assert [%{"id" => ^id1}, %{"id" => ^id2}] =
|
||||||
Enum.sort_by(json_response_and_validate_schema(conn, :ok), & &1["id"])
|
Enum.sort_by(json_response_and_validate_schema(conn, :ok), & &1["id"])
|
||||||
end
|
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
|
describe "getting statuses by ids with restricted unauthenticated for local and remote" do
|
||||||
setup do: local_and_remote_activities()
|
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)
|
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||||
|
|
||||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
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) == []
|
assert json_response_and_validate_schema(res_conn, 200) == []
|
||||||
end
|
end
|
||||||
|
@ -945,7 +955,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
test "if user is authenticated", %{local: local, remote: remote} do
|
test "if user is authenticated", %{local: local, remote: remote} do
|
||||||
%{conn: conn} = oauth_access(["read"])
|
%{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
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
||||||
end
|
end
|
||||||
|
@ -957,7 +967,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||||
|
|
||||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
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
|
remote_id = remote.id
|
||||||
assert [%{"id" => ^remote_id}] = json_response_and_validate_schema(res_conn, 200)
|
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
|
test "if user is authenticated", %{local: local, remote: remote} do
|
||||||
%{conn: conn} = oauth_access(["read"])
|
%{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
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
||||||
end
|
end
|
||||||
|
@ -978,7 +988,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||||
|
|
||||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
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
|
local_id = local.id
|
||||||
assert [%{"id" => ^local_id}] = json_response_and_validate_schema(res_conn, 200)
|
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
|
test "if user is authenticated", %{local: local, remote: remote} do
|
||||||
%{conn: conn} = oauth_access(["read"])
|
%{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
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
||||||
end
|
end
|
||||||
|
@ -2241,7 +2251,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get("/api/v1/statuses/?ids[]=#{activity.id}")
|
|> get("/api/v1/statuses/?id[]=#{activity.id}")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert [
|
assert [
|
||||||
|
@ -2254,7 +2264,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
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)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert [
|
assert [
|
||||||
|
|
Loading…
Reference in a new issue