Make AntiLinkSpamPolicy history-aware
This commit is contained in:
parent
d877d2a4e7
commit
997f08b350
@ -9,6 +9,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy do
|
|||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def history_awareness, do: :auto
|
||||||
|
|
||||||
# has the user successfully posted before?
|
# has the user successfully posted before?
|
||||||
defp old_user?(%User{} = u) do
|
defp old_user?(%User{} = u) do
|
||||||
u.note_count > 0 || u.follower_count > 0
|
u.note_count > 0 || u.follower_count > 0
|
||||||
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
|
|
||||||
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy
|
alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy
|
||||||
|
|
||||||
@linkless_message %{
|
@linkless_message %{
|
||||||
@ -49,11 +50,23 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||||||
|
|
||||||
assert user.note_count == 0
|
assert user.note_count == 0
|
||||||
|
|
||||||
message =
|
message = %{
|
||||||
@linkful_message
|
"type" => "Create",
|
||||||
|> Map.put("actor", user.ap_id)
|
"actor" => user.ap_id,
|
||||||
|
"object" => %{
|
||||||
|
"formerRepresentations" => %{
|
||||||
|
"type" => "OrderedCollection",
|
||||||
|
"orderedItems" => [
|
||||||
|
%{
|
||||||
|
"content" => "<a href='https://example.com'>hi world!</a>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"content" => "mew"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{:reject, _} = AntiLinkSpamPolicy.filter(message)
|
{:reject, _} = MRF.filter_one(AntiLinkSpamPolicy, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it allows posts with links for local users" do
|
test "it allows posts with links for local users" do
|
||||||
@ -67,6 +80,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||||||
|
|
||||||
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
|
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it disallows posts with links in history" do
|
||||||
|
user = insert(:user, local: false)
|
||||||
|
|
||||||
|
assert user.note_count == 0
|
||||||
|
|
||||||
|
message =
|
||||||
|
@linkful_message
|
||||||
|
|> Map.put("actor", user.ap_id)
|
||||||
|
|
||||||
|
{:reject, _} = AntiLinkSpamPolicy.filter(message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with old user" do
|
describe "with old user" do
|
||||||
|
Loading…
Reference in New Issue
Block a user