1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoValidator do
9 alias Pleroma.EctoType.ActivityPub.ObjectValidators
12 import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
17 field(:id, ObjectValidators.ObjectID, primary_key: true)
19 field(:object, ObjectValidators.ObjectID)
20 field(:actor, ObjectValidators.ObjectID)
21 field(:to, ObjectValidators.Recipients, default: [])
22 field(:cc, ObjectValidators.Recipients, default: [])
25 def cast_and_validate(data) do
31 def cast_data(data) do
36 def changeset(struct, data) do
38 |> cast(data, __schema__(:fields))
41 defp validate_data(data_cng) do
43 |> validate_inclusion(:type, ["Undo"])
44 |> validate_required([:id, :type, :object, :actor, :to, :cc])
45 |> validate_actor_presence()
46 |> validate_object_presence()
47 |> validate_undo_rights()
50 def validate_undo_rights(cng) do
51 actor = get_field(cng, :actor)
52 object = get_field(cng, :object)
54 with %Activity{data: %{"actor" => object_actor}} <- Activity.get_by_ap_id(object),
55 true <- object_actor != actor do
57 |> add_error(:actor, "not the same as object actor")