Deletion: Handle the case of pruned objects.
This commit is contained in:
parent
84bb116ae3
commit
5367a00257
9 changed files with 166 additions and 8 deletions
|
|
@ -1554,10 +1554,23 @@ defmodule Pleroma.User do
|
|||
|> Stream.run()
|
||||
end
|
||||
|
||||
defp delete_activity(%{data: %{"type" => "Create", "object" => object}}, user) do
|
||||
{:ok, delete_data, _} = Builder.delete(user, object)
|
||||
defp delete_activity(%{data: %{"type" => "Create", "object" => object}} = activity, user) do
|
||||
with {_, %Object{}} <- {:find_object, Object.get_by_ap_id(object)},
|
||||
{:ok, delete_data, _} <- Builder.delete(user, object) do
|
||||
Pipeline.common_pipeline(delete_data, local: user.local)
|
||||
else
|
||||
{:find_object, nil} ->
|
||||
# We have the create activity, but not the object, it was probably pruned.
|
||||
# Insert a tombstone and try again
|
||||
with {:ok, tombstone_data, _} <- Builder.tombstone(user.ap_id, object),
|
||||
{:ok, _tombstone} <- Object.create(tombstone_data) do
|
||||
delete_activity(activity, user)
|
||||
end
|
||||
|
||||
Pipeline.common_pipeline(delete_data, local: user.local)
|
||||
e ->
|
||||
Logger.error("Could not delete #{object} created by #{activity.data["ap_id"]}")
|
||||
Logger.error("Error: #{inspect(e)}")
|
||||
end
|
||||
end
|
||||
|
||||
defp delete_activity(%{data: %{"type" => type}} = activity, user)
|
||||
|
|
|
|||
|
|
@ -62,6 +62,16 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
|||
}, []}
|
||||
end
|
||||
|
||||
@spec tombstone(String.t(), String.t()) :: {:ok, map(), keyword()}
|
||||
def tombstone(actor, id) do
|
||||
{:ok,
|
||||
%{
|
||||
"id" => id,
|
||||
"actor" => actor,
|
||||
"type" => "Tombstone"
|
||||
}, []}
|
||||
end
|
||||
|
||||
@spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
|
||||
def like(actor, object) do
|
||||
with {:ok, data, meta} <- object_action(actor, object) do
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
|
|||
Page
|
||||
Question
|
||||
Video
|
||||
Tombstone
|
||||
}
|
||||
def validate_data(cng) do
|
||||
cng
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.Types
|
||||
alias Pleroma.Web.ActivityPub.Pipeline
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
|
|
@ -720,6 +722,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
) do
|
||||
with {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
|
||||
{:ok, activity}
|
||||
else
|
||||
{:error, {:validate_object, _}} = e ->
|
||||
# Check if we have a create activity for this
|
||||
with {:ok, object_id} <- Types.ObjectID.cast(data["object"]),
|
||||
%Activity{data: %{"actor" => actor}} <-
|
||||
Activity.create_by_object_ap_id(object_id) |> Repo.one(),
|
||||
# We have one, insert a tombstone and retry
|
||||
{:ok, tombstone_data, _} <- Builder.tombstone(actor, object_id),
|
||||
{:ok, _tombstone} <- Object.create(tombstone_data) do
|
||||
handle_incoming(data)
|
||||
else
|
||||
_ -> e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -83,16 +83,35 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
end
|
||||
|
||||
def delete(activity_id, user) do
|
||||
with {_, %Activity{data: %{"object" => _}} = activity} <-
|
||||
{:find_activity, Activity.get_by_id_with_object(activity_id)},
|
||||
%Object{} = object <- Object.normalize(activity),
|
||||
with {_, %Activity{data: %{"object" => _, "type" => "Create"}} = activity} <-
|
||||
{:find_activity, Activity.get_by_id(activity_id)},
|
||||
{_, %Object{} = object, _} <-
|
||||
{:find_object, Object.normalize(activity, false), activity},
|
||||
true <- User.superuser?(user) || user.ap_id == object.data["actor"],
|
||||
{:ok, delete_data, _} <- Builder.delete(user, object.data["id"]),
|
||||
{:ok, delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do
|
||||
{:ok, delete}
|
||||
else
|
||||
{:find_activity, _} -> {:error, :not_found}
|
||||
_ -> {:error, dgettext("errors", "Could not delete")}
|
||||
{:find_activity, _} ->
|
||||
{:error, :not_found}
|
||||
|
||||
{:find_object, nil, %Activity{data: %{"actor" => actor, "object" => object}}} ->
|
||||
# We have the create activity, but not the object, it was probably pruned.
|
||||
# Insert a tombstone and try again
|
||||
with {:ok, tombstone_data, _} <- Builder.tombstone(actor, object),
|
||||
{:ok, _tombstone} <- Object.create(tombstone_data) do
|
||||
delete(activity_id, user)
|
||||
else
|
||||
_ ->
|
||||
Logger.error(
|
||||
"Could not insert tombstone for missing object on deletion. Object is #{object}."
|
||||
)
|
||||
|
||||
{:error, dgettext("errors", "Could not delete")}
|
||||
end
|
||||
|
||||
_ ->
|
||||
{:error, dgettext("errors", "Could not delete")}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue