Do not strip reported statuses when configured not to
This commit is contained in:
parent
481f50bcfd
commit
6f047cc308
@ -228,6 +228,7 @@ config :pleroma, :instance,
|
||||
max_pinned_statuses: 1,
|
||||
attachment_links: false,
|
||||
max_report_comment_size: 1000,
|
||||
report_strip_status: true,
|
||||
safe_dm_mentions: false,
|
||||
healthcheck: false,
|
||||
remote_post_retention_days: 90,
|
||||
|
@ -815,6 +815,12 @@ config :pleroma, :config_description, [
|
||||
1_000
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :report_strip_status,
|
||||
label: "Report strip status",
|
||||
type: :boolean,
|
||||
description: "Strip status when closing or resolving a report."
|
||||
},
|
||||
%{
|
||||
key: :safe_dm_mentions,
|
||||
label: "Safe DM mentions",
|
||||
|
@ -748,22 +748,21 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||
ActivityPub.fetch_activities([], params, :offset)
|
||||
end
|
||||
|
||||
def update_report_state(%Activity{} = activity, state)
|
||||
when state in @strip_status_report_states do
|
||||
{:ok, stripped_activity} = strip_report_status_data(activity)
|
||||
|
||||
new_data =
|
||||
activity.data
|
||||
|> Map.put("state", state)
|
||||
|> Map.put("object", stripped_activity.data["object"])
|
||||
|
||||
activity
|
||||
|> Changeset.change(data: new_data)
|
||||
|> Repo.update()
|
||||
defp maybe_strip_report_status(data, state) do
|
||||
with true <- Config.get([:instance, :report_strip_status]),
|
||||
true <- state in @strip_status_report_states,
|
||||
{:ok, stripped_activity} = strip_report_status_data(%Activity{data: data}) do
|
||||
data |> Map.put("object", stripped_activity.data["object"])
|
||||
else
|
||||
_ -> data
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|> Changeset.change(data: new_data)
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.Report do
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
|
||||
def extract_report_info(
|
||||
@ -16,10 +17,38 @@ defmodule Pleroma.Web.AdminAPI.Report do
|
||||
status_ap_ids
|
||||
|> Enum.reject(&is_nil(&1))
|
||||
|> Enum.map(fn
|
||||
act when is_map(act) -> Activity.get_by_ap_id_with_object(act["id"])
|
||||
act when is_binary(act) -> Activity.get_by_ap_id_with_object(act)
|
||||
act when is_map(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)
|
||||
|
||||
%{report: report, user: user, account: account, statuses: statuses}
|
||||
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"]
|
||||
},
|
||||
recipients: [user.ap_id],
|
||||
object: %Object{
|
||||
data: %{
|
||||
"actor" => user.ap_id,
|
||||
"type" => "Note",
|
||||
"content" => act["content"],
|
||||
"published" => act["published"],
|
||||
"to" => [],
|
||||
"cc" => []
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -1154,6 +1154,30 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
assert activity_id == activity.data["id"]
|
||||
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
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
activity = insert(:note_activity, user: target_user)
|
||||
|
Loading…
Reference in New Issue
Block a user