Merge branch 'from/upstream-develop/tusooa/no-strip-report' into 'develop'

Give admin the choice to not strip reported statuses

Closes #2887

See merge request pleroma/pleroma!3773
This commit is contained in:
tusooa 2022-11-12 17:55:50 +00:00
commit 1b0e47b79b
7 changed files with 107 additions and 15 deletions

View file

@ -223,6 +223,7 @@
max_pinned_statuses: 1, max_pinned_statuses: 1,
attachment_links: false, attachment_links: false,
max_report_comment_size: 1000, max_report_comment_size: 1000,
report_strip_status: true,
safe_dm_mentions: false, safe_dm_mentions: false,
healthcheck: false, healthcheck: false,
remote_post_retention_days: 90, remote_post_retention_days: 90,

View file

@ -815,6 +815,12 @@
1_000 1_000
] ]
}, },
%{
key: :report_strip_status,
label: "Report strip status",
type: :boolean,
description: "Strip associated statuses in reports to ids when closed/resolved, otherwise keep a copy"
},
%{ %{
key: :safe_dm_mentions, key: :safe_dm_mentions,
label: "Safe DM mentions", label: "Safe DM mentions",

View file

@ -49,6 +49,7 @@ To add configuration to your config file, you can copy it from the base config.
* `autofollowing_nicknames`: Set to nicknames of (local) users that automatically follows every newly registered user. * `autofollowing_nicknames`: Set to nicknames of (local) users that automatically follows every newly registered user.
* `attachment_links`: Set to true to enable automatically adding attachment link text to statuses. * `attachment_links`: Set to true to enable automatically adding attachment link text to statuses.
* `max_report_comment_size`: The maximum size of the report comment (Default: `1000`). * `max_report_comment_size`: The maximum size of the report comment (Default: `1000`).
* `report_strip_status`: Strip associated statuses in reports to ids when closed/resolved, otherwise keep a copy.
* `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). Default: `false`. * `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). Default: `false`.
* `healthcheck`: If set to true, system data will be shown on ``/api/v1/pleroma/healthcheck``. * `healthcheck`: If set to true, system data will be shown on ``/api/v1/pleroma/healthcheck``.
* `remote_post_retention_days`: The default amount of days to retain remote posts when pruning the database. * `remote_post_retention_days`: The default amount of days to retain remote posts when pruning the database.

View file

@ -748,22 +748,21 @@ def get_reports(params, page, page_size) do
ActivityPub.fetch_activities([], params, :offset) ActivityPub.fetch_activities([], params, :offset)
end end
def update_report_state(%Activity{} = activity, state) defp maybe_strip_report_status(data, state) do
when state in @strip_status_report_states do with true <- Config.get([:instance, :report_strip_status]),
{:ok, stripped_activity} = strip_report_status_data(activity) true <- state in @strip_status_report_states,
{:ok, stripped_activity} = strip_report_status_data(%Activity{data: data}) do
new_data = data |> Map.put("object", stripped_activity.data["object"])
activity.data else
|> Map.put("state", state) _ -> data
|> Map.put("object", stripped_activity.data["object"]) end
activity
|> Changeset.change(data: new_data)
|> Repo.update()
end end
def update_report_state(%Activity{} = activity, state) when state in @supported_report_states do def update_report_state(%Activity{} = activity, state) when state in @supported_report_states do
new_data = Map.put(activity.data, "state", state) new_data =
activity.data
|> Map.put("state", state)
|> maybe_strip_report_status(state)
activity activity
|> Changeset.change(data: new_data) |> Changeset.change(data: new_data)

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.AdminAPI.Report do defmodule Pleroma.Web.AdminAPI.Report do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User alias Pleroma.User
def extract_report_info( def extract_report_info(
@ -16,10 +17,42 @@ def extract_report_info(
status_ap_ids status_ap_ids
|> Enum.reject(&is_nil(&1)) |> Enum.reject(&is_nil(&1))
|> Enum.map(fn |> Enum.map(fn
act when is_map(act) -> Activity.get_by_ap_id_with_object(act["id"]) act when is_map(act) ->
act when is_binary(act) -> Activity.get_by_ap_id_with_object(act) Activity.get_by_ap_id_with_object(act["id"]) || make_fake_activity(act, user)
act when is_binary(act) ->
Activity.get_by_ap_id_with_object(act)
end) end)
%{report: report, user: user, account: account, statuses: statuses} %{report: report, user: user, account: account, statuses: statuses}
end end
defp make_fake_activity(act, user) do
%Activity{
id: "pleroma:fake",
data: %{
"actor" => user.ap_id,
"type" => "Create",
"to" => [],
"cc" => [],
"object" => act["id"],
"published" => act["published"],
"id" => act["id"],
"context" => "pleroma:fake"
},
recipients: [user.ap_id],
object: %Object{
data: %{
"actor" => user.ap_id,
"type" => "Note",
"content" => act["content"],
"published" => act["published"],
"to" => [],
"cc" => [],
"id" => act["id"],
"context" => "pleroma:fake"
}
}
}
end
end end

View file

@ -54,6 +54,32 @@ test "returns report by its id", %{conn: conn} do
assert notes["content"] == "this is an admin note" assert notes["content"] == "this is an admin note"
end end
test "renders reported content even if the status is deleted", %{conn: conn} do
[reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user)
activity = Activity.normalize(activity)
{:ok, %{id: report_id}} =
CommonAPI.report(reporter, %{
account_id: target_user.id,
comment: "I feel offended",
status_ids: [activity.id]
})
CommonAPI.delete(activity.id, target_user)
response =
conn
|> get("/api/pleroma/admin/reports/#{report_id}")
|> json_response_and_validate_schema(:ok)
assert response["id"] == report_id
assert [status] = response["statuses"]
assert activity.data["id"] == status["uri"]
assert activity.object.data["content"] == status["content"]
end
test "returns 404 when report id is invalid", %{conn: conn} do test "returns 404 when report id is invalid", %{conn: conn} do
conn = get(conn, "/api/pleroma/admin/reports/test") conn = get(conn, "/api/pleroma/admin/reports/test")

View file

@ -1154,6 +1154,32 @@ test "updates report state" do
assert activity_id == activity.data["id"] assert activity_id == activity.data["id"]
end end
test "updates report state, don't strip when report_strip_status is false" do
clear_config([:instance, :report_strip_status], false)
[reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user)
{:ok, %Activity{id: report_id, data: report_data}} =
CommonAPI.report(reporter, %{
account_id: target_user.id,
comment: "I feel offended",
status_ids: [activity.id]
})
{:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
assert report.data["state"] == "resolved"
[reported_user, reported_activity] = report.data["object"]
assert reported_user == target_user.ap_id
assert is_map(reported_activity)
assert reported_activity["content"] ==
report_data["object"] |> Enum.at(1) |> Map.get("content")
end
test "does not update report state when state is unsupported" do test "does not update report state when state is unsupported" do
[reporter, target_user] = insert_pair(:user) [reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user) activity = insert(:note_activity, user: target_user)