1
0
Fork 0
forked from mirrors/akkoma

Merge branch 'fix/blocked-user-boosts' into 'develop'

ActivityPub.ex: do not return boosted statuses from blocked users.

See merge request pleroma/pleroma!111
This commit is contained in:
lambda 2018-04-28 13:49:12 +00:00
commit a7a40bb8f1
2 changed files with 23 additions and 1 deletions

View file

@ -313,7 +313,10 @@ defp restrict_recent(query, _) do
defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do
blocks = info["blocks"] || []
from(activity in query, where: fragment("not (? = ANY(?))", activity.actor, ^blocks))
from(activity in query,
where: fragment("not (? = ANY(?))", activity.actor, ^blocks),
where: fragment("not (?->'to' \\?| ?)", activity.data, ^blocks)
)
end
defp restrict_blocked(query, _), do: query

View file

@ -2,6 +2,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
use Pleroma.DataCase
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
alias Pleroma.{Activity, Object, User}
alias Pleroma.Builders.ActivityBuilder
@ -130,12 +131,15 @@ test "retrieves activities that have a given context" do
test "doesn't return blocked activities" do
activity_one = insert(:note_activity)
activity_two = insert(:note_activity)
activity_three = insert(:note_activity)
user = insert(:user)
booster = insert(:user)
{:ok, user} = User.block(user, %{ap_id: activity_one.data["actor"]})
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
refute Enum.member?(activities, activity_one)
{:ok, user} = User.unblock(user, %{ap_id: activity_one.data["actor"]})
@ -143,11 +147,26 @@ test "doesn't return blocked activities" do
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
assert Enum.member?(activities, activity_one)
{:ok, user} = User.block(user, %{ap_id: activity_three.data["actor"]})
{:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
%Activity{} = boost_activity = Activity.get_create_activity_by_object_ap_id(id)
activity_three = Repo.get(Activity, activity_three.id)
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
assert Enum.member?(activities, activity_two)
refute Enum.member?(activities, activity_three)
refute Enum.member?(activities, boost_activity)
assert Enum.member?(activities, activity_one)
activities = ActivityPub.fetch_activities([], %{"blocking_user" => nil})
assert Enum.member?(activities, activity_two)
assert Enum.member?(activities, activity_three)
assert Enum.member?(activities, boost_activity)
assert Enum.member?(activities, activity_one)
end