Elixir 1.19: Inject @compile autoload opt to MRF policies
Descriptions of MRF policies are gathered at compile-time and use Pleroma.Docs.Generator.list_behaviour_implementations func, which depends on modules implementing the queried behaviour to be loaded. Otherwise descriptions for MRFs can be missing from the AdminAPI route. Note: @behaviour cannot be injected in the __using__ macro. It causes a loop in the compiler which leads to memory exhaustion. Hence why @behaviour is still defined separately in the MRFs.
This commit is contained in:
parent
6744a86fe3
commit
17a563aeb4
34 changed files with 105 additions and 34 deletions
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy do
|
||||||
@moduledoc "Adds expiration to all local Create activities"
|
@moduledoc "Adds expiration to all local Create activities"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(activity) do
|
def filter(activity) do
|
||||||
activity =
|
activity =
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
|
||||||
|
@moduledoc "Prevent followbots from following with a bit of heuristic"
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@moduledoc "Prevent followbots from following with a bit of heuristic"
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
||||||
|
|
||||||
# XXX: this should become User.normalize_by_ap_id() or similar, really.
|
# XXX: this should become User.normalize_by_ap_id() or similar, really.
|
||||||
defp normalize_by_ap_id(%{"id" => id}), do: User.get_cached_by_ap_id(id)
|
defp normalize_by_ap_id(%{"id" => id}), do: User.get_cached_by_ap_id(id)
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,11 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy do
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,13 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiMentionSpamPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.AntiMentionSpamPolicy do
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp user_has_posted?(%User{} = u), do: u.note_count > 0
|
defp user_has_posted?(%User{} = u), do: u.note_count > 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,12 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
|
||||||
require Logger
|
|
||||||
@moduledoc "Drop and log everything received"
|
@moduledoc "Drop and log everything received"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(activity) do
|
def filter(activity) do
|
||||||
Logger.debug("REJECTING #{inspect(activity)}")
|
Logger.debug("REJECTING #{inspect(activity)}")
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.EmojiPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.EmojiPolicy do
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
alias Pleroma.Object.Updater
|
alias Pleroma.Object.Updater
|
||||||
|
|
@ -10,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EmojiPolicy do
|
||||||
|
|
||||||
@moduledoc "Reject or force-unlisted emojis with certain URLs or names"
|
@moduledoc "Reject or force-unlisted emojis with certain URLs or names"
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp config_remove_url do
|
defp config_remove_url do
|
||||||
Pleroma.Config.get([:mrf_emoji, :remove_url], [])
|
Pleroma.Config.get([:mrf_emoji, :remove_url], [])
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,13 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
|
defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
|
||||||
alias Pleroma.Object
|
|
||||||
|
|
||||||
@moduledoc "Ensure a re: is prepended on replies to a post with a Subject"
|
@moduledoc "Ensure a re: is prepended on replies to a post with a Subject"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
alias Pleroma.Object
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
|
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
|
||||||
|
|
||||||
def history_awareness, do: :auto
|
def history_awareness, do: :auto
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,15 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(activity) do
|
def filter(activity) do
|
||||||
with follower_nickname <- Config.get([:mrf_follow_bot, :follower_nickname]),
|
with follower_nickname <- Config.get([:mrf_follow_bot, :follower_nickname]),
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,12 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy do
|
||||||
alias Pleroma.User
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
||||||
@moduledoc "Remove bot posts from federated timeline"
|
@moduledoc "Remove bot posts from federated timeline"
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,14 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceMention do
|
defmodule Pleroma.Web.ActivityPub.MRF.ForceMention do
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp get_author(url) do
|
defp get_author(url) do
|
||||||
with %Object{data: %{"actor" => actor}} <- Object.normalize(url, fetch: false),
|
with %Object{data: %{"actor" => actor}} <- Object.normalize(url, fetch: false),
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent do
|
defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent do
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def history_awareness, do: :auto
|
def history_awareness, do: :auto
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicy do
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
|
|
@ -14,7 +16,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicy do
|
||||||
Note: This MRF Policy is always enabled, if you want to disable it you have to set empty lists.
|
Note: This MRF Policy is always enabled, if you want to disable it you have to set empty lists.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def history_awareness, do: :manual
|
def history_awareness, do: :manual
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,14 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
|
||||||
|
@moduledoc "Block activities with too much mentions (configurable)"
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
@moduledoc "Block activities with too much mentions (configurable)"
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
||||||
|
|
||||||
defp delist_activity(activity, threshold) when threshold > 0 do
|
defp delist_activity(activity, threshold) when threshold > 0 do
|
||||||
follower_collection = User.get_cached_by_ap_id(activity["actor"]).follower_address
|
follower_collection = User.get_cached_by_ap_id(activity["actor"]).follower_address
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy do
|
||||||
@moduledoc "Force a quote line into the message content."
|
@moduledoc "Force a quote line into the message content."
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp build_inline_quote(template, url) do
|
defp build_inline_quote(template, url) do
|
||||||
quote_line = String.replace(template, "{url}", "<a href=\"#{url}\">#{url}</a>")
|
quote_line = String.replace(template, "{url}", "<a href=\"#{url}\">#{url}</a>")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
||||||
|
@moduledoc "Reject or Word-Replace activities with a keyword or regex"
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
alias Pleroma.Web.ActivityPub.MRF.Utils
|
alias Pleroma.Web.ActivityPub.MRF.Utils
|
||||||
|
|
||||||
@moduledoc "Reject or Word-Replace activities with a keyword or regex"
|
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp string_matches?(string, pattern) when is_binary(pattern) do
|
defp string_matches?(string, pattern) when is_binary(pattern) do
|
||||||
String.contains?(string, pattern)
|
String.contains?(string, pattern)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
||||||
@moduledoc "Preloads any attachments in the MediaProxy cache by prefetching them"
|
@moduledoc "Preloads any attachments in the MediaProxy cache by prefetching them"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.HTTP
|
alias Pleroma.HTTP
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicy do
|
||||||
@moduledoc "Block activities which mention a user"
|
@moduledoc "Block activities which mention a user"
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(%{"type" => "Create"} = activity) do
|
def filter(%{"type" => "Create"} = activity) do
|
||||||
reject_actors = Pleroma.Config.get([:mrf_mention, :actors], [])
|
reject_actors = Pleroma.Config.get([:mrf_mention, :actors], [])
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
|
||||||
@moduledoc "Filter local activities which have no content"
|
@moduledoc "Filter local activities which have no content"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Web.Endpoint
|
alias Pleroma.Web.Endpoint
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
|
||||||
@moduledoc "Does nothing (lets the messages go through unmodified)"
|
@moduledoc "Does nothing (lets the messages go through unmodified)"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(activity) do
|
def filter(activity) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy do
|
||||||
@moduledoc "Ensure no content placeholder is present (such as the dot from mastodon)"
|
@moduledoc "Ensure no content placeholder is present (such as the dot from mastodon)"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def history_awareness, do: :auto
|
def history_awareness, do: :auto
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
|
defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
|
||||||
@moduledoc "Scrub configured hypertext markup"
|
@moduledoc "Scrub configured hypertext markup"
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.HTML
|
alias Pleroma.HTML
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def history_awareness, do: :auto
|
def history_awareness, do: :auto
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NsfwApiPolicy do
|
||||||
- `unlist`: Unlist all detected NSFW content? Default: `false`
|
- `unlist`: Unlist all detected NSFW content? Default: `false`
|
||||||
- `reject`: Reject all detected NSFW content (takes precedence)? Default: `false`
|
- `reject`: Reject all detected NSFW content (takes precedence)? Default: `false`
|
||||||
"""
|
"""
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Constants
|
alias Pleroma.Constants
|
||||||
alias Pleroma.HTTP
|
alias Pleroma.HTTP
|
||||||
|
|
@ -46,7 +48,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.NsfwApiPolicy do
|
||||||
require Logger
|
require Logger
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@policy :mrf_nsfw_api
|
@policy :mrf_nsfw_api
|
||||||
|
|
||||||
def build_request_url(url) do
|
def build_request_url(url) do
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
|
||||||
|
@moduledoc "Filter activities depending on their age"
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
@moduledoc "Filter activities depending on their age"
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
||||||
|
|
||||||
defp check_date(%{"object" => %{"published" => published}} = activity) do
|
defp check_date(%{"object" => %{"published" => published}} = activity) do
|
||||||
with %DateTime{} = now <- DateTime.utc_now(),
|
with %DateTime{} = now <- DateTime.utc_now(),
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.Policy do
|
||||||
}
|
}
|
||||||
@callback history_awareness() :: :auto | :manual
|
@callback history_awareness() :: :auto | :manual
|
||||||
@optional_callbacks config_description: 0, history_awareness: 0, id_filter: 1
|
@optional_callbacks config_description: 0, history_awareness: 0, id_filter: 1
|
||||||
|
|
||||||
|
defmacro __using__(_) do
|
||||||
|
quote do
|
||||||
|
# Otherwise Pleroma.Docs.Generator.list_behaviour_implementations fails
|
||||||
|
# since the Elixir compiler doesn't automatically load the module since v1.19.
|
||||||
|
@compile {:autoload, true}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.QuietReply do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
QuietReply alters the scope of activities from local users when replying by enforcing them to be "Unlisted" or "Quiet Public". This delivers the activity to all the expected recipients and instances, but it will not be published in the Federated / The Whole Known Network timelines. It will still be published to the Home timelines of the user's followers and visible to anyone who opens the thread.
|
QuietReply alters the scope of activities from local users when replying by enforcing them to be "Unlisted" or "Quiet Public". This delivers the activity to all the expected recipients and instances, but it will not be published in the Federated / The Whole Known Network timelines. It will still be published to the Home timelines of the user's followers and visible to anyone who opens the thread.
|
||||||
"""
|
"""
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def history_awareness, do: :auto
|
def history_awareness, do: :auto
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.QuoteToLinkTagPolicy do
|
||||||
@moduledoc "Force a Link tag for posts quoting another post. (may break outgoing federation of quote posts with older Pleroma versions)"
|
@moduledoc "Force a Link tag for posts quoting another post. (may break outgoing federation of quote posts with older Pleroma versions)"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
|
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do
|
defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do
|
||||||
@moduledoc "Rejects non-public (followers-only, direct) activities"
|
@moduledoc "Rejects non-public (followers-only, direct) activities"
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.RemoteReportPolicy do
|
||||||
@moduledoc "Drop remote reports if they don't contain enough information."
|
@moduledoc "Drop remote reports if they don't contain enough information."
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||||
@moduledoc "Filter activities depending on their origin instance"
|
@moduledoc "Filter activities depending on their origin instance"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.FollowingRelationship
|
alias Pleroma.FollowingRelationship
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,14 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
||||||
|
@moduledoc "Detect new emojis by their shortcode and steals them"
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
|
|
||||||
@moduledoc "Detect new emojis by their shortcode and steals them"
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
||||||
|
|
||||||
defp accept_host?(host), do: host in Config.get([:mrf_steal_emoji, :hosts], [])
|
defp accept_host?(host), do: host in Config.get([:mrf_steal_emoji, :hosts], [])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,14 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicy do
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp lookup_subchain(actor) do
|
defp lookup_subchain(actor) do
|
||||||
with matches <- Config.get([:mrf_subchain, :match_actor]),
|
with matches <- Config.get([:mrf_subchain, :match_actor]),
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||||
alias Pleroma.User
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Apply policies based on user tags
|
Apply policies based on user tags
|
||||||
|
|
||||||
|
|
@ -18,6 +16,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||||
- `mrf_tag:disable-remote-subscription`: Reject non-local follow requests
|
- `mrf_tag:disable-remote-subscription`: Reject non-local follow requests
|
||||||
- `mrf_tag:disable-any-subscription`: Reject any follow requests
|
- `mrf_tag:disable-any-subscription`: Reject any follow requests
|
||||||
"""
|
"""
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,13 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do
|
||||||
alias Pleroma.Config
|
|
||||||
|
|
||||||
@moduledoc "Accept-list of users from specified instances"
|
@moduledoc "Accept-list of users from specified instances"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
alias Pleroma.Config
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp filter_by_list(activity, []), do: {:ok, activity}
|
defp filter_by_list(activity, []), do: {:ok, activity}
|
||||||
|
|
||||||
defp filter_by_list(%{"actor" => actor} = activity, allow_list) do
|
defp filter_by_list(%{"actor" => actor} = activity, allow_list) do
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicy do
|
||||||
@moduledoc "Filter activities which belong to certain activity vocabularies"
|
@moduledoc "Filter activities which belong to certain activity vocabularies"
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
|
use Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(%{"type" => "Undo", "object" => object} = activity) do
|
def filter(%{"type" => "Undo", "object" => object} = activity) do
|
||||||
with {:ok, _} <- filter(object) do
|
with {:ok, _} <- filter(object) do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue