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
13 import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
18 field(:id, ObjectValidators.ObjectID, primary_key: true)
20 field(:object, ObjectValidators.ObjectID)
21 field(:actor, ObjectValidators.ObjectID)
22 field(:to, ObjectValidators.Recipients, default: [])
23 field(:cc, ObjectValidators.Recipients, default: [])
26 def cast_and_validate(data) do
32 def cast_data(data) do
37 def changeset(struct, data) do
39 |> cast(data, __schema__(:fields))
42 defp validate_data(data_cng) do
44 |> validate_inclusion(:type, ["Undo"])
45 |> validate_required([:id, :type, :object, :actor, :to, :cc])
46 |> validate_undo_actor(:actor)
47 |> validate_object_presence()
48 |> validate_undo_rights()
51 def validate_undo_rights(cng) do
52 actor = get_field(cng, :actor)
53 object = get_field(cng, :object)
55 with %Activity{data: %{"actor" => object_actor}} <- Activity.get_by_ap_id(object),
56 true <- object_actor != actor do
58 |> add_error(:actor, "not the same as object actor")
64 defp validate_undo_actor(cng, field_name) do
65 validate_change(cng, field_name, fn field_name, actor ->
66 case User.get_cached_by_ap_id(actor) do
68 _ -> [{field_name, "can't find user"}]