Fix deletion not deleting relevant actions.

This commit is contained in:
Roger Braun 2017-08-16 16:29:25 +02:00
parent 2ab1d915e3
commit 552cfdbe11
3 changed files with 12 additions and 0 deletions

View file

@ -15,11 +15,17 @@ defmodule Pleroma.Activity do
where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id))) where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
end end
# Wrong name, only returns create activities
def all_by_object_ap_id_q(ap_id) do def all_by_object_ap_id_q(ap_id) do
from activity in Activity, from activity in Activity,
where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id)) where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
end end
def all_non_create_by_object_ap_id_q(ap_id) do
from activity in Activity,
where: fragment("(?)->>'object' = ?", activity.data, ^to_string(ap_id))
end
def all_by_object_ap_id(ap_id) do def all_by_object_ap_id(ap_id) do
Repo.all(all_by_object_ap_id_q(ap_id)) Repo.all(all_by_object_ap_id_q(ap_id))
end end

View file

@ -7,6 +7,7 @@ defmodule Pleroma.Web.OStatus.DeleteHandler do
with id <- XML.string_from_xpath("//id", entry), with id <- XML.string_from_xpath("//id", entry),
object when not is_nil(object) <- Object.get_by_ap_id(id) do object when not is_nil(object) <- Object.get_by_ap_id(id) do
Repo.delete(object) Repo.delete(object)
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id))
Repo.delete_all(Activity.all_by_object_ap_id_q(id)) Repo.delete_all(Activity.all_by_object_ap_id_q(id))
nil nil
end end

View file

@ -9,12 +9,17 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
test "it removes the mentioned activity" do test "it removes the mentioned activity" do
note = insert(:note_activity) note = insert(:note_activity)
second_note = insert(:note_activity) second_note = insert(:note_activity)
user = insert(:user)
object = Object.get_by_ap_id(note.data["object"]["id"])
{:ok, like, object} = Pleroma.Web.ActivityPub.ActivityPub.like(user, object)
incoming = File.read!("test/fixtures/delete.xml") incoming = File.read!("test/fixtures/delete.xml")
|> String.replace("tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status", note.data["object"]["id"]) |> String.replace("tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status", note.data["object"]["id"])
{:ok, []} = OStatus.handle_incoming(incoming) {:ok, []} = OStatus.handle_incoming(incoming)
refute Repo.get(Activity, note.id) refute Repo.get(Activity, note.id)
refute Repo.get(Activity, like.id)
refute Object.get_by_ap_id(note.data["object"]["id"]) refute Object.get_by_ap_id(note.data["object"]["id"])
assert Repo.get(Activity, second_note.id) assert Repo.get(Activity, second_note.id)
assert Object.get_by_ap_id(second_note.data["object"]["id"]) assert Object.get_by_ap_id(second_note.data["object"]["id"])