1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
9 alias Pleroma.EctoType.ActivityPub.ObjectValidators
13 import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
20 import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
26 field(:deleted_activity_id, ObjectValidators.ObjectID)
29 def cast_data(data) do
31 |> cast(data, __schema__(:fields))
34 def add_deleted_activity_id(cng) do
39 with %Activity{id: id} <- Activity.get_create_by_object_ap_id(object) do
41 |> put_change(:deleted_activity_id, id)
59 defp validate_data(cng) do
61 |> validate_required([:id, :type, :actor, :to, :cc, :object])
62 |> validate_inclusion(:type, ["Delete"])
63 |> validate_delete_actor(:actor)
64 |> validate_modification_rights(:messages_delete)
65 |> validate_object_or_user_presence(allowed_types: @deletable_types)
66 |> add_deleted_activity_id()
69 def do_not_federate?(cng) do
73 def cast_and_validate(data) do
79 defp validate_delete_actor(cng, field_name) do
80 validate_change(cng, field_name, fn field_name, actor ->
81 case User.get_cached_by_ap_id(actor) do
83 _ -> [{field_name, "can't find user"}]