defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
use Ecto.Schema
+ alias Pleroma.Activity
alias Pleroma.Web.ActivityPub.ObjectValidators.Types
import Ecto.Changeset
field(:actor, Types.ObjectID)
field(:to, Types.Recipients, default: [])
field(:cc, Types.Recipients, default: [])
+ field(:deleted_activity_id)
field(:object, Types.ObjectID)
end
|> cast(data, __schema__(:fields))
end
+ def add_deleted_activity_id(cng) do
+ object =
+ cng
+ |> get_field(:object)
+
+ with %Activity{id: id} <- Activity.get_create_by_object_ap_id(object) do
+ cng
+ |> put_change(:deleted_activity_id, id)
+ else
+ _ -> cng
+ end
+ end
+
def validate_data(cng) do
cng
|> validate_required([:id, :type, :actor, :to, :cc, :object])
|> validate_inclusion(:type, ["Delete"])
|> validate_same_domain()
|> validate_object_or_user_presence()
+ |> add_deleted_activity_id()
end
def validate_same_domain(cng) do
end
test "it is valid for a post deletion", %{valid_post_delete: valid_post_delete} do
- assert match?({:ok, _, _}, ObjectValidator.validate(valid_post_delete, []))
+ {:ok, valid_post_delete_u, _} = ObjectValidator.validate(valid_post_delete, [])
+
+ assert valid_post_delete_u["deleted_activity_id"]
end
test "it is valid for a user deletion", %{valid_user_delete: valid_user_delete} do