From 8302cdb5dc2b2f74d87f7b36a5ed67e29ea129c0 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Mar 2019 10:47:04 +0100 Subject: [PATCH 1/6] Expand "to" of delete activities --- lib/pleroma/web/activity_pub/activity_pub.ex | 5 ++++- test/web/activity_pub/activity_pub_test.exs | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 8d3116839..3650d330a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -305,11 +305,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do user = User.get_cached_by_ap_id(actor) + to = object.data["to"] || [] ++ object.data["cc"] || + [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + data = %{ "type" => "Delete", "actor" => actor, "object" => id, - "to" => [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + "to" => Enum.uniq(to) } with {:ok, _} <- Object.delete(object), diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index a6f8b822a..0abb18303 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -591,6 +591,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert Repo.get(Object, object.id).data["type"] == "Tombstone" end + + test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do + user = insert(:user) + note = insert(:note_activity) + object = Object.get_by_ap_id(note.data["object"]["id"]) + object = Kernel.put_in(object.data["to"], [user.ap_id]) + {:ok, delete} = ActivityPub.delete(object) + + assert user.ap_id in delete.data["to"] + end end describe "timeline post-processing" do From aab86698a5356e26fe68c650f277913497aac3e9 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Mar 2019 10:47:04 +0100 Subject: [PATCH 2/6] Expand "to" of delete activities --- lib/pleroma/web/activity_pub/activity_pub.ex | 5 ++++- test/web/activity_pub/activity_pub_test.exs | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 783491b67..bff3025ed 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -310,11 +310,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do user = User.get_cached_by_ap_id(actor) + to = object.data["to"] || [] ++ object.data["cc"] || + [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + data = %{ "type" => "Delete", "actor" => actor, "object" => id, - "to" => [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + "to" => Enum.uniq(to) } with {:ok, _} <- Object.delete(object), diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index f4029896c..e607c7f4d 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -691,6 +691,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do user = Repo.get(User, user.id) assert user.info.note_count == 10 end + + test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do + user = insert(:user) + note = insert(:note_activity) + object = Object.get_by_ap_id(note.data["object"]["id"]) + object = Kernel.put_in(object.data["to"], [user.ap_id]) + {:ok, delete} = ActivityPub.delete(object) + + assert user.ap_id in delete.data["to"] + end end describe "timeline post-processing" do From 1445dc25d451f1146acd58ba596ebf5bf37ce6f5 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Mar 2019 11:18:16 +0100 Subject: [PATCH 3/6] fix format --- lib/pleroma/web/activity_pub/activity_pub.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index bff3025ed..98639883e 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -310,7 +310,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do user = User.get_cached_by_ap_id(actor) - to = object.data["to"] || [] ++ object.data["cc"] || + to = + object.data["to"] || [] ++ object.data["cc"] || [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] data = %{ From 28d5b40d0afddaca6797e2b72c2e89624e68f967 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Tue, 5 Mar 2019 23:15:22 +0100 Subject: [PATCH 4/6] Add handling of objects not in database --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 ++++++++-- test/web/activity_pub/activity_pub_test.exs | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 98639883e..7e7a43c55 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -311,8 +311,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do user = User.get_cached_by_ap_id(actor) to = - object.data["to"] || [] ++ object.data["cc"] || - [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + case Object.get_cached_by_ap_id(id) do + nil -> + [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + + object -> + object.data["to"] || [] ++ object.data["cc"] || + [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + end data = %{ "type" => "Delete", diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index e607c7f4d..10c5258d0 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -691,12 +691,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do user = Repo.get(User, user.id) assert user.info.note_count == 10 end - + test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do user = insert(:user) note = insert(:note_activity) - object = Object.get_by_ap_id(note.data["object"]["id"]) - object = Kernel.put_in(object.data["to"], [user.ap_id]) + + {:ok, object} = + Object.get_by_ap_id(note.data["object"]["id"]) + |> Object.change(%{ + data: %{ + "actor" => note.data["object"]["actor"], + "id" => note.data["object"]["id"], + "to" => [user.ap_id], + "type" => "Note" + } + }) + |> Object.update_and_set_cache() + {:ok, delete} = ActivityPub.delete(object) assert user.ap_id in delete.data["to"] From 6a69ece437e4c2b503b8ec8cd5de2a4a63519f02 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Thu, 7 Mar 2019 11:53:15 +0100 Subject: [PATCH 5/6] Revert existing object check --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 7e7a43c55..98639883e 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -311,14 +311,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do user = User.get_cached_by_ap_id(actor) to = - case Object.get_cached_by_ap_id(id) do - nil -> - [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] - - object -> - object.data["to"] || [] ++ object.data["cc"] || - [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] - end + object.data["to"] || [] ++ object.data["cc"] || + [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] data = %{ "type" => "Delete", From c2faae70dfc138efbeb3edccf97c22c2546a665a Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Thu, 7 Mar 2019 12:26:03 +0100 Subject: [PATCH 6/6] Adjust delete activity audience to match the deleted object --- lib/pleroma/web/activity_pub/activity_pub.ex | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 98639883e..adb42b9ab 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -309,16 +309,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do user = User.get_cached_by_ap_id(actor) - - to = - object.data["to"] || [] ++ object.data["cc"] || - [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + to = object.data["to"] || [] ++ object.data["cc"] || [] data = %{ "type" => "Delete", "actor" => actor, "object" => id, - "to" => Enum.uniq(to) + "to" => to } with {:ok, _} <- Object.delete(object),