1f863f0a36
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
Objects who got updated would just pass through several of the MRF policies, undoing moderation in some situations. In the relevant cases we now check not only for Create activities, but also Update activities. I checked which ones checked explicitly on type Create using `grep '"type" => "Create"' lib/pleroma/web/activity_pub/mrf/*`. The following from that list have not been changed: * lib/pleroma/web/activity_pub/mrf/follow_bot_policy.ex * Not relevant for moderation * lib/pleroma/web/activity_pub/mrf/keyword_policy.ex * Already had a test for Update * lib/pleroma/web/activity_pub/mrf/object_age_policy.ex * In practice only relevant when fetching old objects (e.g. through Like or Announce). These are always wrapped in a Create. * lib/pleroma/web/activity_pub/mrf/reject_non_public.ex * We don't allow changing scope with Update, so not relevant here
66 lines
1.7 KiB
Elixir
66 lines
1.7 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy do
|
|
@moduledoc "Adds expiration to all local Create/Update activities"
|
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
|
|
@impl true
|
|
def filter(activity) do
|
|
activity =
|
|
if note?(activity) and local?(activity) do
|
|
maybe_add_expiration(activity)
|
|
else
|
|
activity
|
|
end
|
|
|
|
{:ok, activity}
|
|
end
|
|
|
|
@impl true
|
|
def describe, do: {:ok, %{}}
|
|
|
|
defp local?(%{"actor" => actor}) do
|
|
String.starts_with?(actor, Pleroma.Web.Endpoint.url())
|
|
end
|
|
|
|
defp note?(%{"type" => type, "object" => %{"type" => "Note"}})
|
|
when type in ["Create", "Update"] do
|
|
true
|
|
end
|
|
|
|
defp note?(_) do
|
|
false
|
|
end
|
|
|
|
defp maybe_add_expiration(activity) do
|
|
days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
|
|
expires_at = DateTime.utc_now() |> Timex.shift(days: days)
|
|
|
|
with %{"expires_at" => existing_expires_at} <- activity,
|
|
:lt <- DateTime.compare(existing_expires_at, expires_at) do
|
|
activity
|
|
else
|
|
_ -> Map.put(activity, "expires_at", expires_at)
|
|
end
|
|
end
|
|
|
|
@impl true
|
|
def config_description do
|
|
%{
|
|
key: :mrf_activity_expiration,
|
|
related_policy: "Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy",
|
|
label: "MRF Activity Expiration Policy",
|
|
description: "Adds automatic expiration to all local activities",
|
|
children: [
|
|
%{
|
|
key: :days,
|
|
type: :integer,
|
|
description: "Default global expiration time for all local activities (in days)",
|
|
suggestions: [90, 365]
|
|
}
|
|
]
|
|
}
|
|
end
|
|
end
|