Anonymize reporter before federating
This commit is contained in:
parent
27d271b4ef
commit
58ec4fd1ee
3 changed files with 52 additions and 2 deletions
|
|
@ -415,6 +415,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
with flag_data <- make_flag_data(params, additional),
|
with flag_data <- make_flag_data(params, additional),
|
||||||
{:ok, activity} <- insert(flag_data, local),
|
{:ok, activity} <- insert(flag_data, local),
|
||||||
{:ok, stripped_activity} <- strip_report_status_data(activity),
|
{:ok, stripped_activity} <- strip_report_status_data(activity),
|
||||||
|
stripped_activity <- maybe_anonymize_reporter(stripped_activity),
|
||||||
_ <- notify_and_stream(activity),
|
_ <- notify_and_stream(activity),
|
||||||
:ok <-
|
:ok <-
|
||||||
maybe_federate(stripped_activity) do
|
maybe_federate(stripped_activity) do
|
||||||
|
|
|
||||||
|
|
@ -875,15 +875,29 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
{:ok, %{activity | data: new_data}}
|
{:ok, %{activity | data: new_data}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_anonymize_reporter(activity) do
|
def get_anonymized_reporter do
|
||||||
with true <- Pleroma.Config.get([:activitypub, :anonymize_reporter]),
|
with true <- Pleroma.Config.get([:activitypub, :anonymize_reporter]),
|
||||||
nickname when is_binary(nickname) <-
|
nickname when is_binary(nickname) <-
|
||||||
Pleroma.Config.get([:activitypub, :anonymize_reporter_local_nickname]),
|
Pleroma.Config.get([:activitypub, :anonymize_reporter_local_nickname]),
|
||||||
%User{ap_id: ap_id, local: true} <- User.get_cached_by_nickname(nickname) do
|
%User{ap_id: ap_id, local: true} <- User.get_cached_by_nickname(nickname) do
|
||||||
|
ap_id
|
||||||
|
else
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def maybe_anonymize_reporter(%Activity{data: data} = activity) do
|
||||||
|
%Activity{activity | data: maybe_anonymize_reporter(data)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def maybe_anonymize_reporter(activity) do
|
||||||
|
ap_id = get_anonymized_reporter()
|
||||||
|
|
||||||
|
if is_binary(ap_id) do
|
||||||
activity
|
activity
|
||||||
|> Map.put("actor", ap_id)
|
|> Map.put("actor", ap_id)
|
||||||
else
|
else
|
||||||
_ -> activity
|
activity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1707,6 +1707,41 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
assert_called(Utils.maybe_federate(%{activity | data: new_data}))
|
assert_called(Utils.maybe_federate(%{activity | data: new_data}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "anonymize reporter from Flag, before federating it, if configured so",
|
||||||
|
%{
|
||||||
|
reporter: reporter,
|
||||||
|
context: context,
|
||||||
|
target_account: target_account,
|
||||||
|
reported_activity: reported_activity,
|
||||||
|
object_ap_id: object_ap_id,
|
||||||
|
content: content
|
||||||
|
} do
|
||||||
|
placeholder = insert(:user)
|
||||||
|
clear_config([:activitypub, :anonymize_reporter], true)
|
||||||
|
clear_config([:activitypub, :anonymize_reporter_local_nickname], placeholder.nickname)
|
||||||
|
# Workaround "could not checkout connection" problem
|
||||||
|
# https://elixirforum.com/t/ecto-timeout-errors-when-wrapping-into-cachex-calls-in-tests/19078/11
|
||||||
|
%User{} = User.get_cached_by_nickname(placeholder.nickname)
|
||||||
|
|
||||||
|
with_mock Utils, [:passthrough], [] do
|
||||||
|
{:ok, activity} =
|
||||||
|
ActivityPub.flag(%{
|
||||||
|
actor: reporter,
|
||||||
|
context: context,
|
||||||
|
account: target_account,
|
||||||
|
statuses: [reported_activity],
|
||||||
|
content: content
|
||||||
|
})
|
||||||
|
|
||||||
|
new_data =
|
||||||
|
activity.data
|
||||||
|
|> put_in(["object"], [target_account.ap_id, object_ap_id])
|
||||||
|
|> Map.put("actor", placeholder.ap_id)
|
||||||
|
|
||||||
|
assert_called(Utils.maybe_federate(%{activity | data: new_data}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test_with_mock "reverts on error",
|
test_with_mock "reverts on error",
|
||||||
%{
|
%{
|
||||||
reporter: reporter,
|
reporter: reporter,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue