mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2026-02-15 17:16:57 +00:00
Allow assigning users to reports
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
parent
d6bec8b6b7
commit
80ede85f75
17 changed files with 402 additions and 7 deletions
|
|
@ -671,6 +671,19 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "assign_report_to_account/2" do
|
||||
test "assigns report to an account" do
|
||||
reporter = insert(:user)
|
||||
target_account = insert(:user)
|
||||
%{id: assigned_id} = insert(:user)
|
||||
|
||||
{:ok, report} = CommonAPI.report(reporter, %{account_id: target_account.id})
|
||||
{:ok, report} = Utils.assign_report_to_account(report, assigned_id)
|
||||
|
||||
assert %{data: %{"assigned_account" => ^assigned_id}} = report
|
||||
end
|
||||
end
|
||||
|
||||
describe "maybe_anonymize_reporter/1" do
|
||||
setup do
|
||||
reporter = insert(:user)
|
||||
|
|
|
|||
|
|
@ -388,6 +388,38 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
test "returns reports with specified assigned user", %{conn: conn, admin: admin} do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
activity = insert(:note_activity, user: target_user)
|
||||
|
||||
{:ok, _report} =
|
||||
CommonAPI.report(reporter, %{
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, %{id: second_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
account_id: target_user.id,
|
||||
comment: "I don't like this user"
|
||||
})
|
||||
|
||||
CommonAPI.assign_report_to_account(second_report_id, admin.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get(report_path(conn, :index, %{assigned_account: admin.id}))
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [open_report] = response["reports"]
|
||||
|
||||
assert length(response["reports"]) == 1
|
||||
assert open_report["id"] == second_report_id
|
||||
|
||||
assert response["total"] == 1
|
||||
end
|
||||
|
||||
test "renders content correctly", %{conn: conn} do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
note = insert(:note, user: target_user, data: %{"content" => "mew 1"})
|
||||
|
|
@ -467,6 +499,66 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/reports/assign_account" do
|
||||
test "assigns account to report", %{conn: conn, admin: admin} do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
activity = insert(:note_activity, user: target_user)
|
||||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
account_id: target_user.id,
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/reports/assign_account", %{
|
||||
"reports" => [
|
||||
%{"assigned_account" => admin.nickname, "id" => report_id}
|
||||
]
|
||||
})
|
||||
|> json_response_and_validate_schema(:no_content)
|
||||
|
||||
activity = Activity.get_by_id_with_user_actor(report_id)
|
||||
assert activity.data["assigned_account"] == admin.id
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} assigned report ##{report_id} (on user @#{activity.user_actor.nickname}) to user #{admin.nickname}"
|
||||
end
|
||||
|
||||
test "unassigns account from report", %{conn: conn, admin: admin} do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
activity = insert(:note_activity, user: target_user)
|
||||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
account_id: target_user.id,
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
CommonAPI.assign_report_to_account(report_id, admin.id)
|
||||
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/reports/assign_account", %{
|
||||
"reports" => [
|
||||
%{"assigned_account" => nil, "id" => report_id}
|
||||
]
|
||||
})
|
||||
|> json_response_and_validate_schema(:no_content)
|
||||
|
||||
activity = Activity.get_by_id_with_user_actor(report_id)
|
||||
assert activity.data["assigned_account"] == nil
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} unassigned report ##{report_id} (on user @#{activity.user_actor.nickname}) from a user"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/reports/:id/notes" do
|
||||
setup %{conn: conn, admin: admin} do
|
||||
clear_config([:instance, :admin_privileges], [:reports_manage_reports])
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
}),
|
||||
AdminAPI.AccountView.render("show.json", %{user: other_user})
|
||||
),
|
||||
assigned_account: nil,
|
||||
statuses: [],
|
||||
notes: [],
|
||||
state: "open",
|
||||
|
|
@ -75,6 +76,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
}),
|
||||
AdminAPI.AccountView.render("show.json", %{user: other_user})
|
||||
),
|
||||
assigned_account: nil,
|
||||
statuses: [StatusView.render("show.json", %{activity: activity})],
|
||||
state: "open",
|
||||
notes: [],
|
||||
|
|
|
|||
|
|
@ -1458,6 +1458,29 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
}
|
||||
} = flag_activity
|
||||
end
|
||||
|
||||
test "assigns report to an account" do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
%{id: assigned} = insert(:user)
|
||||
|
||||
{:ok, %Activity{id: report_id}} = CommonAPI.report(reporter, %{account_id: target_user.id})
|
||||
|
||||
{:ok, activity} = CommonAPI.assign_report_to_account(report_id, assigned)
|
||||
|
||||
assert %{data: %{"assigned_account" => ^assigned}} = activity
|
||||
end
|
||||
|
||||
test "unassigns report from account" do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
%{id: assigned} = insert(:user)
|
||||
|
||||
{:ok, %Activity{id: report_id}} = CommonAPI.report(reporter, %{account_id: target_user.id})
|
||||
|
||||
CommonAPI.assign_report_to_account(report_id, assigned)
|
||||
{:ok, activity} = CommonAPI.assign_report_to_account(report_id, nil)
|
||||
|
||||
refute Map.has_key?(activity.data, "assigned_account")
|
||||
end
|
||||
end
|
||||
|
||||
describe "reblog muting" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue