Transmogrifier: Actually store who deleted a note.

This commit is contained in:
lain 2019-10-11 11:25:45 +02:00
parent 29647dfd09
commit 9b963064eb
3 changed files with 17 additions and 11 deletions

View file

@ -412,12 +412,14 @@ def delete(%User{ap_id: ap_id, follower_address: follower_address} = user) do
def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, options \\ []) do def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, options \\ []) do
local = Keyword.get(options, :local, true) local = Keyword.get(options, :local, true)
activity_id = Keyword.get(options, :activity_id, nil) activity_id = Keyword.get(options, :activity_id, nil)
actor = Keyword.get(options, :actor, actor)
user = User.get_cached_by_ap_id(actor) user = User.get_cached_by_ap_id(actor)
to = (object.data["to"] || []) ++ (object.data["cc"] || []) to = (object.data["to"] || []) ++ (object.data["cc"] || [])
with {:ok, object, activity} <- Object.delete(object), with {:ok, object, activity} <- Object.delete(object),
data <- %{ data <-
%{
"type" => "Delete", "type" => "Delete",
"actor" => actor, "actor" => actor,
"object" => id, "object" => id,

View file

@ -646,7 +646,8 @@ def handle_incoming(
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor), {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
{:ok, object} <- get_obj_helper(object_id), {:ok, object} <- get_obj_helper(object_id),
:ok <- Containment.contain_origin(actor.ap_id, object.data), :ok <- Containment.contain_origin(actor.ap_id, object.data),
{:ok, activity} <- ActivityPub.delete(object, local: false, activity_id: id) do {:ok, activity} <-
ActivityPub.delete(object, local: false, activity_id: id, actor: actor.ap_id) do
{:ok, activity} {:ok, activity}
else else
nil -> nil ->

View file

@ -682,6 +682,7 @@ test "it works for incoming update activities which lock the account" do
test "it works for incoming deletes" do test "it works for incoming deletes" do
activity = insert(:note_activity) activity = insert(:note_activity)
deleting_user = insert(:user)
data = data =
File.read!("test/fixtures/mastodon-delete.json") File.read!("test/fixtures/mastodon-delete.json")
@ -694,12 +695,14 @@ test "it works for incoming deletes" do
data = data =
data data
|> Map.put("object", object) |> Map.put("object", object)
|> Map.put("actor", activity.data["actor"]) |> Map.put("actor", deleting_user.ap_id)
{:ok, %Activity{local: false, data: %{"id" => id}}} = Transmogrifier.handle_incoming(data) {:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} =
Transmogrifier.handle_incoming(data)
assert id == data["id"] assert id == data["id"]
refute Activity.get_by_id(activity.id) refute Activity.get_by_id(activity.id)
assert actor == deleting_user.ap_id
end end
test "it fails for incoming deletes with spoofed origin" do test "it fails for incoming deletes with spoofed origin" do