Add maybe_anonymize_reporter/1
This commit is contained in:
parent
29be5018b0
commit
27d271b4ef
4 changed files with 92 additions and 1 deletions
|
|
@ -364,7 +364,9 @@ config :pleroma, :activitypub,
|
||||||
note_replies_output_limit: 5,
|
note_replies_output_limit: 5,
|
||||||
sign_object_fetches: true,
|
sign_object_fetches: true,
|
||||||
authorized_fetch_mode: false,
|
authorized_fetch_mode: false,
|
||||||
client_api_enabled: false
|
client_api_enabled: false,
|
||||||
|
anonymize_reporter: false,
|
||||||
|
anonymize_reporter_local_nickname: ""
|
||||||
|
|
||||||
config :pleroma, :streamer,
|
config :pleroma, :streamer,
|
||||||
workers: 3,
|
workers: 3,
|
||||||
|
|
|
||||||
|
|
@ -1790,6 +1790,23 @@ config :pleroma, :config_description, [
|
||||||
key: :client_api_enabled,
|
key: :client_api_enabled,
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
description: "Allow client to server ActivityPub interactions"
|
description: "Allow client to server ActivityPub interactions"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
key: :anonymize_reporter,
|
||||||
|
type: :boolean,
|
||||||
|
label: "Anonymize local reports",
|
||||||
|
description:
|
||||||
|
"If true, replace local reporters with the designated local user for the copy to be sent to remote servers"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
key: :anonymize_reporter_local_nickname,
|
||||||
|
type: :string,
|
||||||
|
label: "Anonymized reporter",
|
||||||
|
description:
|
||||||
|
"The nickname of the designated local user that replaces the actual reporter in the copy to be sent to remote servers",
|
||||||
|
suggestions: [
|
||||||
|
"lain"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -875,6 +875,18 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
{:ok, %{activity | data: new_data}}
|
{:ok, %{activity | data: new_data}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def maybe_anonymize_reporter(activity) do
|
||||||
|
with true <- Pleroma.Config.get([:activitypub, :anonymize_reporter]),
|
||||||
|
nickname when is_binary(nickname) <-
|
||||||
|
Pleroma.Config.get([:activitypub, :anonymize_reporter_local_nickname]),
|
||||||
|
%User{ap_id: ap_id, local: true} <- User.get_cached_by_nickname(nickname) do
|
||||||
|
activity
|
||||||
|
|> Map.put("actor", ap_id)
|
||||||
|
else
|
||||||
|
_ -> activity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update_activity_visibility(activity, visibility) when visibility in @valid_visibilities do
|
def update_activity_visibility(activity, visibility) when visibility in @valid_visibilities do
|
||||||
[to, cc, recipients] =
|
[to, cc, recipients] =
|
||||||
activity
|
activity
|
||||||
|
|
|
||||||
|
|
@ -670,4 +670,64 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "maybe_anonymize_reporter/1" do
|
||||||
|
setup do
|
||||||
|
reporter = insert(:user)
|
||||||
|
report = %{"actor" => reporter.ap_id}
|
||||||
|
|
||||||
|
%{
|
||||||
|
placeholder: insert(:user),
|
||||||
|
reporter: reporter,
|
||||||
|
report: report
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "anonymize when configured correctly", %{
|
||||||
|
placeholder: placeholder,
|
||||||
|
report: report
|
||||||
|
} do
|
||||||
|
clear_config([:activitypub, :anonymize_reporter], true)
|
||||||
|
clear_config([:activitypub, :anonymize_reporter_local_nickname], placeholder.nickname)
|
||||||
|
|
||||||
|
assert %{"actor" => placeholder.ap_id} == Utils.maybe_anonymize_reporter(report)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "do not anonymize when disabled", %{
|
||||||
|
placeholder: placeholder,
|
||||||
|
reporter: reporter,
|
||||||
|
report: report
|
||||||
|
} do
|
||||||
|
clear_config([:activitypub, :anonymize_reporter], false)
|
||||||
|
clear_config([:activitypub, :anonymize_reporter_local_nickname], placeholder.nickname)
|
||||||
|
|
||||||
|
assert %{"actor" => reporter.ap_id} == Utils.maybe_anonymize_reporter(report)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "do not anonymize when user does not exist", %{
|
||||||
|
placeholder: placeholder,
|
||||||
|
reporter: reporter,
|
||||||
|
report: report
|
||||||
|
} do
|
||||||
|
clear_config([:activitypub, :anonymize_reporter], true)
|
||||||
|
|
||||||
|
clear_config(
|
||||||
|
[:activitypub, :anonymize_reporter_local_nickname],
|
||||||
|
placeholder.nickname <> "MewMew"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert %{"actor" => reporter.ap_id} == Utils.maybe_anonymize_reporter(report)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "do not anonymize when user is not local", %{
|
||||||
|
reporter: reporter,
|
||||||
|
report: report
|
||||||
|
} do
|
||||||
|
placeholder = insert(:user, local: false)
|
||||||
|
clear_config([:activitypub, :anonymize_reporter], true)
|
||||||
|
clear_config([:activitypub, :anonymize_reporter_local_nickname], placeholder.nickname)
|
||||||
|
|
||||||
|
assert %{"actor" => reporter.ap_id} == Utils.maybe_anonymize_reporter(report)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue