Merge branch 'mutes-blocks-pagination' into 'develop'
Support pagination of blocks and mutes Closes #642 See merge request pleroma/pleroma!3080
This commit is contained in:
commit
6d7dc1241c
|
@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Media preview proxy (requires `ffmpeg` and `ImageMagick` to be installed and media proxy to be enabled; see `:media_preview_proxy` config for more details).
|
- Media preview proxy (requires `ffmpeg` and `ImageMagick` to be installed and media proxy to be enabled; see `:media_preview_proxy` config for more details).
|
||||||
- Pleroma API: Importing the mutes users from CSV files.
|
- Pleroma API: Importing the mutes users from CSV files.
|
||||||
- Experimental websocket-based federation between Pleroma instances.
|
- Experimental websocket-based federation between Pleroma instances.
|
||||||
|
- Support pagination of blocks and mutes
|
||||||
- App metrics: ability to restrict access to specified IP whitelist.
|
- App metrics: ability to restrict access to specified IP whitelist.
|
||||||
- Configuration: Add `:instance, autofollowing_nicknames` setting to provide a way to make accounts automatically follow new users that register on the local Pleroma instance.
|
- Configuration: Add `:instance, autofollowing_nicknames` setting to provide a way to make accounts automatically follow new users that register on the local Pleroma instance.
|
||||||
|
|
||||||
|
|
|
@ -335,6 +335,7 @@ def mutes_operation do
|
||||||
operationId: "AccountController.mutes",
|
operationId: "AccountController.mutes",
|
||||||
description: "Accounts the user has muted.",
|
description: "Accounts the user has muted.",
|
||||||
security: [%{"oAuth" => ["follow", "read:mutes"]}],
|
security: [%{"oAuth" => ["follow", "read:mutes"]}],
|
||||||
|
parameters: pagination_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Accounts", "application/json", array_of_accounts())
|
200 => Operation.response("Accounts", "application/json", array_of_accounts())
|
||||||
}
|
}
|
||||||
|
@ -348,6 +349,7 @@ def blocks_operation do
|
||||||
operationId: "AccountController.blocks",
|
operationId: "AccountController.blocks",
|
||||||
description: "View your blocks. See also accounts/:id/{block,unblock}",
|
description: "View your blocks. See also accounts/:id/{block,unblock}",
|
||||||
security: [%{"oAuth" => ["read:blocks"]}],
|
security: [%{"oAuth" => ["read:blocks"]}],
|
||||||
|
parameters: pagination_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Accounts", "application/json", array_of_accounts())
|
200 => Operation.response("Accounts", "application/json", array_of_accounts())
|
||||||
}
|
}
|
||||||
|
|
|
@ -442,15 +442,27 @@ def follow_by_uri(%{body_params: %{uri: uri}} = conn, _) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "GET /api/v1/mutes"
|
@doc "GET /api/v1/mutes"
|
||||||
def mutes(%{assigns: %{user: user}} = conn, _) do
|
def mutes(%{assigns: %{user: user}} = conn, params) do
|
||||||
users = User.muted_users(user, _restrict_deactivated = true)
|
users =
|
||||||
render(conn, "index.json", users: users, for: user, as: :user)
|
user
|
||||||
|
|> User.muted_users_relation(_restrict_deactivated = true)
|
||||||
|
|> Pleroma.Pagination.fetch_paginated(Map.put(params, :skip_order, true))
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> add_link_headers(users)
|
||||||
|
|> render("index.json", users: users, for: user, as: :user)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "GET /api/v1/blocks"
|
@doc "GET /api/v1/blocks"
|
||||||
def blocks(%{assigns: %{user: user}} = conn, _) do
|
def blocks(%{assigns: %{user: user}} = conn, params) do
|
||||||
users = User.blocked_users(user, _restrict_deactivated = true)
|
users =
|
||||||
render(conn, "index.json", users: users, for: user, as: :user)
|
user
|
||||||
|
|> User.blocked_users_relation(_restrict_deactivated = true)
|
||||||
|
|> Pleroma.Pagination.fetch_paginated(Map.put(params, :skip_order, true))
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> add_link_headers(users)
|
||||||
|
|> render("index.json", users: users, for: user, as: :user)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "GET /api/v1/endorsements"
|
@doc "GET /api/v1/endorsements"
|
||||||
|
|
|
@ -1509,28 +1509,103 @@ test "returns an empty list on a bad request", %{conn: conn} do
|
||||||
|
|
||||||
test "getting a list of mutes" do
|
test "getting a list of mutes" do
|
||||||
%{user: user, conn: conn} = oauth_access(["read:mutes"])
|
%{user: user, conn: conn} = oauth_access(["read:mutes"])
|
||||||
other_user = insert(:user)
|
%{id: id1} = other_user1 = insert(:user)
|
||||||
|
%{id: id2} = other_user2 = insert(:user)
|
||||||
|
%{id: id3} = other_user3 = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_relationships} = User.mute(user, other_user)
|
{:ok, _user_relationships} = User.mute(user, other_user1)
|
||||||
|
{:ok, _user_relationships} = User.mute(user, other_user2)
|
||||||
|
{:ok, _user_relationships} = User.mute(user, other_user3)
|
||||||
|
|
||||||
conn = get(conn, "/api/v1/mutes")
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/mutes")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
other_user_id = to_string(other_user.id)
|
assert [id1, id2, id3] == Enum.map(result, & &1["id"])
|
||||||
assert [%{"id" => ^other_user_id}] = json_response_and_validate_schema(conn, 200)
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/mutes?limit=1")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert [%{"id" => ^id1}] = result
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/mutes?since_id=#{id1}")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/mutes?since_id=#{id1}&max_id=#{id3}")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert [%{"id" => ^id2}] = result
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/mutes?since_id=#{id1}&limit=1")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert [%{"id" => ^id2}] = result
|
||||||
end
|
end
|
||||||
|
|
||||||
test "getting a list of blocks" do
|
test "getting a list of blocks" do
|
||||||
%{user: user, conn: conn} = oauth_access(["read:blocks"])
|
%{user: user, conn: conn} = oauth_access(["read:blocks"])
|
||||||
other_user = insert(:user)
|
%{id: id1} = other_user1 = insert(:user)
|
||||||
|
%{id: id2} = other_user2 = insert(:user)
|
||||||
|
%{id: id3} = other_user3 = insert(:user)
|
||||||
|
|
||||||
{:ok, _user_relationship} = User.block(user, other_user)
|
{:ok, _user_relationship} = User.block(user, other_user1)
|
||||||
|
{:ok, _user_relationship} = User.block(user, other_user3)
|
||||||
|
{:ok, _user_relationship} = User.block(user, other_user2)
|
||||||
|
|
||||||
conn =
|
result =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> get("/api/v1/blocks")
|
|> get("/api/v1/blocks")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
other_user_id = to_string(other_user.id)
|
assert [id1, id2, id3] == Enum.map(result, & &1["id"])
|
||||||
assert [%{"id" => ^other_user_id}] = json_response_and_validate_schema(conn, 200)
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/blocks?limit=1")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert [%{"id" => ^id1}] = result
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/blocks?since_id=#{id1}")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/blocks?since_id=#{id1}&max_id=#{id3}")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert [%{"id" => ^id2}] = result
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/blocks?since_id=#{id1}&limit=1")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert [%{"id" => ^id2}] = result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue