Remove unneeded code
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
0f33698747
commit
612e6284b4
4 changed files with 0 additions and 194 deletions
|
@ -1,95 +0,0 @@
|
||||||
# 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.BlockNotificationPolicy do
|
|
||||||
@moduledoc "Notify local users upon remote block and unblock."
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
||||||
|
|
||||||
alias Pleroma.Config
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Web.CommonAPI
|
|
||||||
|
|
||||||
defp is_block_or_unblock(%{"type" => "Block", "object" => object}),
|
|
||||||
do: {true, "blocked", object}
|
|
||||||
|
|
||||||
defp is_block_or_unblock(%{
|
|
||||||
"type" => "Undo",
|
|
||||||
"object" => %{"type" => "Block", "object" => object}
|
|
||||||
}),
|
|
||||||
do: {true, "unblocked", object}
|
|
||||||
|
|
||||||
defp is_block_or_unblock(_), do: {false, nil, nil}
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
def filter(message) do
|
|
||||||
with {true, action, object} <- is_block_or_unblock(message),
|
|
||||||
%User{} = actor <- User.get_cached_by_ap_id(message["actor"]),
|
|
||||||
true <- actor.is_active,
|
|
||||||
%User{} = recipient <- User.get_cached_by_ap_id(object) do
|
|
||||||
bot_user = Pleroma.Config.get([:mrf_block_notification_policy, :user])
|
|
||||||
|
|
||||||
replacements = %{
|
|
||||||
"actor" => actor.nickname,
|
|
||||||
"target" => recipient.nickname,
|
|
||||||
"action" => action
|
|
||||||
}
|
|
||||||
|
|
||||||
msg =
|
|
||||||
Regex.replace(
|
|
||||||
~r/{([a-z]+)?}/,
|
|
||||||
Pleroma.Config.get([:mrf_block_notification_policy, :message]),
|
|
||||||
fn _, match ->
|
|
||||||
replacements[match]
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
_reply =
|
|
||||||
CommonAPI.post(User.get_by_nickname(bot_user), %{
|
|
||||||
status: msg,
|
|
||||||
visibility: Pleroma.Config.get([:mrf_block_notification_policy, :visibility])
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
{:ok, message}
|
|
||||||
end
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
def describe do
|
|
||||||
mrf_block_notification_policy = Config.get(:mrf_block_notification_policy)
|
|
||||||
|
|
||||||
{:ok, %{mrf_block_notification_policy: mrf_block_notification_policy}}
|
|
||||||
end
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
def config_description do
|
|
||||||
%{
|
|
||||||
key: :mrf_block_notification_policy,
|
|
||||||
related_policy: "Pleroma.Web.ActivityPub.MRF.BlockNotificationPolicy",
|
|
||||||
description: "Notify local users upon remote block.",
|
|
||||||
children: [
|
|
||||||
%{
|
|
||||||
key: :message,
|
|
||||||
type: :string,
|
|
||||||
label: "Message",
|
|
||||||
description:
|
|
||||||
"The message to send when someone is blocked or unblocked; use {actor}, {target}, and {action} variables",
|
|
||||||
suggestions: ["@{actor} {action} @{target}"]
|
|
||||||
},
|
|
||||||
%{
|
|
||||||
key: :user,
|
|
||||||
type: :string,
|
|
||||||
label: "Block User",
|
|
||||||
description: "The user account that announces a block"
|
|
||||||
},
|
|
||||||
%{
|
|
||||||
key: :visibility,
|
|
||||||
type: :string,
|
|
||||||
label: "Visibility",
|
|
||||||
description: "The visibility of block messages",
|
|
||||||
suggestions: ["public", "unlisted", "private", "direct"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -173,9 +173,7 @@ defp validate_page_url(page_url) when is_binary(page_url) do
|
||||||
validate_tld = @config_impl.get([Pleroma.Formatter, :validate_tld])
|
validate_tld = @config_impl.get([Pleroma.Formatter, :validate_tld])
|
||||||
|
|
||||||
page_url
|
page_url
|
||||||
|> IO.inspect()
|
|
||||||
|> Linkify.Parser.url?(validate_tld: validate_tld)
|
|> Linkify.Parser.url?(validate_tld: validate_tld)
|
||||||
|> IO.inspect()
|
|
||||||
|> parse_uri(page_url)
|
|> parse_uri(page_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -200,7 +198,6 @@ defp validate_page_url(_), do: :error
|
||||||
defp parse_uri(true, url) do
|
defp parse_uri(true, url) do
|
||||||
url
|
url
|
||||||
|> URI.parse()
|
|> URI.parse()
|
||||||
|> IO.inspect()
|
|
||||||
|> validate_page_url
|
|> validate_page_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
# 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.BlockNotificationPolicyTest do
|
|
||||||
use Pleroma.DataCase, async: true
|
|
||||||
|
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
||||||
alias Pleroma.Web.ActivityPub.MRF.BlockNotificationPolicy
|
|
||||||
|
|
||||||
import Pleroma.Factory
|
|
||||||
|
|
||||||
setup do:
|
|
||||||
clear_config(:mrf_block_notification_policy,
|
|
||||||
message: "@{actor} {action} @{target}",
|
|
||||||
user: "beholder",
|
|
||||||
visibility: "public"
|
|
||||||
)
|
|
||||||
|
|
||||||
setup do
|
|
||||||
%{
|
|
||||||
beholder: insert(:user, nickname: "beholder"),
|
|
||||||
butthurt: insert(:user, nickname: "butthurt"),
|
|
||||||
sneed: insert(:user, nickname: "sneed")
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
test "creates messages when user blocks other user", %{
|
|
||||||
butthurt: butthurt,
|
|
||||||
sneed: sneed,
|
|
||||||
beholder: beholder
|
|
||||||
} do
|
|
||||||
activities = ActivityPub.fetch_user_activities(beholder, beholder, %{})
|
|
||||||
assert length(activities) == 0
|
|
||||||
|
|
||||||
message = %{
|
|
||||||
"type" => "Block",
|
|
||||||
"object" => sneed.ap_id,
|
|
||||||
"actor" => butthurt.ap_id
|
|
||||||
}
|
|
||||||
|
|
||||||
assert {:ok, _object} = BlockNotificationPolicy.filter(message)
|
|
||||||
|
|
||||||
activities = ActivityPub.fetch_user_activities(beholder, beholder, %{})
|
|
||||||
assert length(activities) == 1
|
|
||||||
|
|
||||||
[head | _tail] = activities
|
|
||||||
|
|
||||||
assert head.object.data["source"]["content"] == "@butthurt blocked @sneed"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "creates messages when user unblocks other user", %{
|
|
||||||
butthurt: butthurt,
|
|
||||||
sneed: sneed,
|
|
||||||
beholder: beholder
|
|
||||||
} do
|
|
||||||
activities = ActivityPub.fetch_user_activities(beholder, beholder, %{})
|
|
||||||
assert length(activities) == 0
|
|
||||||
|
|
||||||
message = %{
|
|
||||||
"type" => "Undo",
|
|
||||||
"object" => %{"type" => "Block", "object" => sneed.ap_id},
|
|
||||||
"actor" => butthurt.ap_id
|
|
||||||
}
|
|
||||||
|
|
||||||
assert {:ok, _object} = BlockNotificationPolicy.filter(message)
|
|
||||||
|
|
||||||
activities = ActivityPub.fetch_user_activities(beholder, beholder, %{})
|
|
||||||
assert length(activities) == 1
|
|
||||||
|
|
||||||
[head | _tail] = activities
|
|
||||||
|
|
||||||
assert head.object.data["source"]["content"] == "@butthurt unblocked @sneed"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "creates no message when the action type isn't block or unblock", %{
|
|
||||||
butthurt: butthurt,
|
|
||||||
sneed: sneed,
|
|
||||||
beholder: beholder
|
|
||||||
} do
|
|
||||||
activities = ActivityPub.fetch_user_activities(beholder, beholder, %{})
|
|
||||||
assert length(activities) == 0
|
|
||||||
|
|
||||||
message = %{
|
|
||||||
"type" => "Note",
|
|
||||||
"object" => sneed.ap_id,
|
|
||||||
"actor" => butthurt.ap_id
|
|
||||||
}
|
|
||||||
|
|
||||||
assert {:ok, _object} = BlockNotificationPolicy.filter(message)
|
|
||||||
|
|
||||||
activities = ActivityPub.fetch_user_activities(beholder, beholder, %{})
|
|
||||||
assert length(activities) == 0
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1235,7 +1235,6 @@ test "registers and logs in without :account_activation_required / :account_appr
|
||||||
assert user
|
assert user
|
||||||
assert user.is_confirmed
|
assert user.is_confirmed
|
||||||
assert user.is_approved
|
assert user.is_approved
|
||||||
refute user.accepts_
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "registers but does not log in with :account_activation_required", %{conn: conn} do
|
test "registers but does not log in with :account_activation_required", %{conn: conn} do
|
||||||
|
|
Loading…
Reference in a new issue