From cd8bdbc761d950587a189bded2dcb02f6247f16d Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Mon, 6 Dec 2021 11:44:17 +0000 Subject: [PATCH 1/2] Make deactivated user check into a subquery Fixes #2792 --- lib/pleroma/activity.ex | 5 ++--- .../web/activity_pub/activity_pub_test.exs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index b88f74f47..c84e96aa2 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -362,11 +362,10 @@ def following_requests_for_actor(%User{ap_id: ap_id}) do end def restrict_deactivated_users(query) do - deactivated_users = + deactivated_users_query = from(u in User.Query.build(%{deactivated: true}), select: u.ap_id) - |> Repo.all() - Activity.Queries.exclude_authors(query, deactivated_users) + from(activity in query, where: activity.actor not in subquery(deactivated_users_query)) end defdelegate search(user, query, options \\ []), to: Pleroma.Activity.Search diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index a61244c76..b57e87247 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -776,6 +776,21 @@ test "doesn't return blocked activities" do assert Enum.member?(activities, activity_one) end + test "doesn't return activities from deactivated users" do + _user = insert(:user) + deactivated = insert(:user) + active = insert(:user) + {:ok, activity_one} = CommonAPI.post(deactivated, %{status: "hey!"}) + {:ok, activity_two} = CommonAPI.post(active, %{status: "yay!"}) + {:ok, _updated_user} = User.set_activation(deactivated, false) + + activities = ActivityPub.fetch_activities([], %{}) + + refute Enum.member?(activities, activity_one) + assert Enum.member?(activities, activity_two) + end + + test "always see your own posts even when they address people you block" do user = insert(:user) blockee = insert(:user) From db46913dcc01e6d5a274f7c82eef44c304d52244 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Mon, 6 Dec 2021 11:50:51 +0000 Subject: [PATCH 2/2] make linter happy --- lib/pleroma/activity.ex | 3 +-- test/pleroma/web/activity_pub/activity_pub_test.exs | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index c84e96aa2..4106feef6 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -362,8 +362,7 @@ def following_requests_for_actor(%User{ap_id: ap_id}) do end def restrict_deactivated_users(query) do - deactivated_users_query = - from(u in User.Query.build(%{deactivated: true}), select: u.ap_id) + deactivated_users_query = from(u in User.Query.build(%{deactivated: true}), select: u.ap_id) from(activity in query, where: activity.actor not in subquery(deactivated_users_query)) end diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index b57e87247..574ef0d71 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -783,14 +783,13 @@ test "doesn't return activities from deactivated users" do {:ok, activity_one} = CommonAPI.post(deactivated, %{status: "hey!"}) {:ok, activity_two} = CommonAPI.post(active, %{status: "yay!"}) {:ok, _updated_user} = User.set_activation(deactivated, false) - + activities = ActivityPub.fetch_activities([], %{}) - + refute Enum.member?(activities, activity_one) assert Enum.member?(activities, activity_two) end - test "always see your own posts even when they address people you block" do user = insert(:user) blockee = insert(:user)