Directly delete an object if the actor is itself

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-04-20 11:33:54 +02:00
parent 00f4c0b02c
commit 0ebb797740
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -622,19 +622,25 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
{:error, :unknown_actor} {:error, :unknown_actor}
{:ok, %Actor{} = actor} -> {:ok, %Actor{} = actor} ->
case is_group_object_gone(object_id) do # If the actor itself is being deleted, no need to check anything other than the object being remote
{:ok, object} -> if remote_actor_is_being_deleted(data) do
if Utils.origin_check_from_id?(actor_url, object_id) || Actions.Delete.delete(actor, actor, false)
Permission.can_delete_group_object?(actor, object) do else
Actions.Delete.delete(object, actor, false) case is_group_object_gone(object_id) do
else # The group object is no longer there, we can remove the element
Logger.warn("Object origin check failed") {:ok, entity} ->
:error if Utils.origin_check_from_id?(actor_url, object_id) ||
end Permission.can_delete_group_object?(actor, entity) do
Actions.Delete.delete(entity, actor, false)
else
Logger.warn("Object origin check failed")
:error
end
{:error, err} -> {:error, err} ->
Logger.debug(inspect(err)) Logger.debug(inspect(err))
{:error, err} {:error, err}
end
end end
end end
end end
@ -1215,4 +1221,9 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
moderator.domain == group.domain moderator.domain == group.domain
end end
end end
defp remote_actor_is_being_deleted(%{"object" => object} = data) do
object_id = Utils.get_url(object)
Utils.get_actor(data) == object_id and not Utils.are_same_origin?(object_id, Endpoint.url())
end
end end