mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-23 15:05:45 +00:00
Merge branch 'feature/auto-reject-follow-requests-blocked' into 'develop'
activitypub: transmogrifier: send reject follow if following does not succeed See merge request pleroma/pleroma!1094
This commit is contained in:
commit
8c9227c1f1
|
@ -438,20 +438,46 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
|
with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
|
||||||
%User{} = follower <- User.get_or_fetch_by_ap_id(follower),
|
%User{} = follower <- User.get_or_fetch_by_ap_id(follower),
|
||||||
{:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
|
{:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
|
||||||
if not User.locked?(followed) do
|
with deny_follow_blocked <- Pleroma.Config.get([:user, :deny_follow_blocked]),
|
||||||
|
{:user_blocked, false} <-
|
||||||
|
{:user_blocked, User.blocks?(followed, follower) && deny_follow_blocked},
|
||||||
|
{:user_locked, false} <- {:user_locked, User.locked?(followed)},
|
||||||
|
{:follow, {:ok, follower}} <- {:follow, User.follow(follower, followed)} do
|
||||||
ActivityPub.accept(%{
|
ActivityPub.accept(%{
|
||||||
to: [follower.ap_id],
|
to: [follower.ap_id],
|
||||||
actor: followed,
|
actor: followed,
|
||||||
object: data,
|
object: data,
|
||||||
local: true
|
local: true
|
||||||
})
|
})
|
||||||
|
else
|
||||||
|
{:user_blocked, true} ->
|
||||||
|
{:ok, _} = Utils.update_follow_state(activity, "reject")
|
||||||
|
|
||||||
User.follow(follower, followed)
|
ActivityPub.reject(%{
|
||||||
|
to: [follower.ap_id],
|
||||||
|
actor: followed,
|
||||||
|
object: data,
|
||||||
|
local: true
|
||||||
|
})
|
||||||
|
|
||||||
|
{:follow, {:error, _}} ->
|
||||||
|
{:ok, _} = Utils.update_follow_state(activity, "reject")
|
||||||
|
|
||||||
|
ActivityPub.reject(%{
|
||||||
|
to: [follower.ap_id],
|
||||||
|
actor: followed,
|
||||||
|
object: data,
|
||||||
|
local: true
|
||||||
|
})
|
||||||
|
|
||||||
|
{:user_locked, true} ->
|
||||||
|
:noop
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
_e -> :error
|
_e ->
|
||||||
|
:error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -215,6 +215,26 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
|
||||||
|
Pleroma.Config.put([:user, :deny_follow_blocked], true)
|
||||||
|
|
||||||
|
user = insert(:user)
|
||||||
|
target = User.get_or_fetch("http://mastodon.example.org/users/admin")
|
||||||
|
|
||||||
|
{:ok, user} = User.block(user, target)
|
||||||
|
|
||||||
|
data =
|
||||||
|
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
|> Map.put("object", user.ap_id)
|
||||||
|
|
||||||
|
{:ok, %Activity{data: %{"id" => id}}} = Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
|
%Activity{} = activity = Activity.get_by_ap_id(id)
|
||||||
|
|
||||||
|
assert activity.data["state"] == "reject"
|
||||||
|
end
|
||||||
|
|
||||||
test "it works for incoming follow requests from hubzilla" do
|
test "it works for incoming follow requests from hubzilla" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue