2020-05-20 08:00:41 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-20 08:00:41 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
|
2023-08-01 04:43:50 -06:00
|
|
|
use Pleroma.Web.ConnCase, async: false
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.ModerationLog
|
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
setup do
|
|
|
|
admin = insert(:user, is_admin: true)
|
|
|
|
token = insert(:oauth_admin_token, user: admin)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, admin)
|
|
|
|
|> assign(:token, token)
|
|
|
|
|
|
|
|
{:ok, %{admin: admin, token: token, conn: conn}}
|
|
|
|
end
|
|
|
|
|
2022-12-14 05:38:48 -07:00
|
|
|
describe "GET /api/v1/pleroma/admin/statuses/:id" do
|
2020-05-20 08:00:41 -06:00
|
|
|
test "not found", %{conn: conn} do
|
|
|
|
assert conn
|
2022-12-14 05:38:48 -07:00
|
|
|
|> get("/api/v1/pleroma/admin/statuses/not_found")
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(:not_found)
|
2020-05-20 08:00:41 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "shows activity", %{conn: conn} do
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
2022-12-14 05:38:48 -07:00
|
|
|
|> get("/api/v1/pleroma/admin/statuses/#{activity.id}")
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(200)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
assert response["id"] == activity.id
|
2020-05-18 01:09:21 -06:00
|
|
|
|
|
|
|
account = response["account"]
|
|
|
|
actor = User.get_by_ap_id(activity.actor)
|
|
|
|
|
|
|
|
assert account["id"] == actor.id
|
|
|
|
assert account["nickname"] == actor.nickname
|
2020-10-12 16:42:27 -06:00
|
|
|
assert account["is_active"] == actor.is_active
|
2020-10-13 13:29:34 -06:00
|
|
|
assert account["is_confirmed"] == actor.is_confirmed
|
2020-05-20 08:00:41 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-14 05:38:48 -07:00
|
|
|
describe "PUT /api/v1/pleroma/admin/statuses/:id" do
|
2020-05-20 08:00:41 -06:00
|
|
|
setup do
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
|
|
|
|
%{id: activity.id}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "toggle sensitive flag", %{conn: conn, id: id, admin: admin} do
|
|
|
|
response =
|
|
|
|
conn
|
2020-05-21 04:03:38 -06:00
|
|
|
|> put_req_header("content-type", "application/json")
|
2022-12-14 05:38:48 -07:00
|
|
|
|> put("/api/v1/pleroma/admin/statuses/#{id}", %{"sensitive" => "true"})
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
assert response["sensitive"]
|
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} updated status ##{id}, set sensitive: 'true'"
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
2020-05-21 04:03:38 -06:00
|
|
|
|> put_req_header("content-type", "application/json")
|
2022-12-14 05:38:48 -07:00
|
|
|
|> put("/api/v1/pleroma/admin/statuses/#{id}", %{"sensitive" => "false"})
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
refute response["sensitive"]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "change visibility flag", %{conn: conn, id: id, admin: admin} do
|
|
|
|
response =
|
|
|
|
conn
|
2020-05-21 04:03:38 -06:00
|
|
|
|> put_req_header("content-type", "application/json")
|
2022-12-14 05:38:48 -07:00
|
|
|
|> put("/api/v1/pleroma/admin/statuses/#{id}", %{visibility: "public"})
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
assert response["visibility"] == "public"
|
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} updated status ##{id}, set visibility: 'public'"
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
2020-05-21 04:03:38 -06:00
|
|
|
|> put_req_header("content-type", "application/json")
|
2022-12-14 05:38:48 -07:00
|
|
|
|> put("/api/v1/pleroma/admin/statuses/#{id}", %{visibility: "private"})
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
assert response["visibility"] == "private"
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
2020-05-21 04:03:38 -06:00
|
|
|
|> put_req_header("content-type", "application/json")
|
2022-12-14 05:38:48 -07:00
|
|
|
|> put("/api/v1/pleroma/admin/statuses/#{id}", %{visibility: "unlisted"})
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
assert response["visibility"] == "unlisted"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns 400 when visibility is unknown", %{conn: conn, id: id} do
|
2020-05-21 04:03:38 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
2022-12-14 05:38:48 -07:00
|
|
|
|> put("/api/v1/pleroma/admin/statuses/#{id}", %{visibility: "test"})
|
2020-05-20 08:00:41 -06:00
|
|
|
|
2020-05-21 04:03:38 -06:00
|
|
|
assert %{"error" => "test - Invalid value for enum."} =
|
|
|
|
json_response_and_validate_schema(conn, :bad_request)
|
2020-05-20 08:00:41 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-14 05:38:48 -07:00
|
|
|
describe "DELETE /api/v1/pleroma/admin/statuses/:id" do
|
2020-05-20 08:00:41 -06:00
|
|
|
setup do
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
|
|
|
|
%{id: activity.id}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes status", %{conn: conn, id: id, admin: admin} do
|
|
|
|
conn
|
2022-12-14 05:38:48 -07:00
|
|
|
|> delete("/api/v1/pleroma/admin/statuses/#{id}")
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(:ok)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
refute Activity.get_by_id(id)
|
|
|
|
|
|
|
|
log_entry = Repo.one(ModerationLog)
|
|
|
|
|
|
|
|
assert ModerationLog.get_log_entry_message(log_entry) ==
|
|
|
|
"@#{admin.nickname} deleted status ##{id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns 404 when the status does not exist", %{conn: conn} do
|
2022-12-14 05:38:48 -07:00
|
|
|
conn = delete(conn, "/api/v1/pleroma/admin/statuses/test")
|
2020-05-20 08:00:41 -06:00
|
|
|
|
2020-05-21 04:03:38 -06:00
|
|
|
assert json_response_and_validate_schema(conn, :not_found) == %{"error" => "Not found"}
|
2020-05-20 08:00:41 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-14 05:38:48 -07:00
|
|
|
describe "GET /api/v1/pleroma/admin/statuses" do
|
2020-05-20 08:00:41 -06:00
|
|
|
test "returns all public and unlisted statuses", %{conn: conn, admin: admin} do
|
|
|
|
blocked = insert(:user)
|
|
|
|
user = insert(:user)
|
|
|
|
User.block(admin, blocked)
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: "@#{admin.nickname}", visibility: "direct"})
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "private"})
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
|
|
|
{:ok, _} = CommonAPI.post(blocked, %{status: ".", visibility: "public"})
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
2022-12-14 05:38:48 -07:00
|
|
|
|> get("/api/v1/pleroma/admin/statuses")
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(200)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
refute "private" in Enum.map(response, & &1["visibility"])
|
|
|
|
assert length(response) == 3
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns only local statuses with local_only on", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
remote_user = insert(:user, local: false, nickname: "archaeme@archae.me")
|
|
|
|
insert(:note_activity, user: user, local: true)
|
|
|
|
insert(:note_activity, user: remote_user, local: false)
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
2022-12-14 05:38:48 -07:00
|
|
|
|> get("/api/v1/pleroma/admin/statuses?local_only=true")
|
2020-05-21 04:03:38 -06:00
|
|
|
|> json_response_and_validate_schema(200)
|
2020-05-20 08:00:41 -06:00
|
|
|
|
|
|
|
assert length(response) == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns private and direct statuses with godmode on", %{conn: conn, admin: admin} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: "@#{admin.nickname}", visibility: "direct"})
|
|
|
|
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "private"})
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
2022-12-14 05:38:48 -07:00
|
|
|
conn = get(conn, "/api/v1/pleroma/admin/statuses?godmode=true")
|
2020-05-21 04:03:38 -06:00
|
|
|
assert json_response_and_validate_schema(conn, 200) |> length() == 3
|
2020-05-20 08:00:41 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|