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.UpdateValidator do
8 alias Pleroma.EctoType.ActivityPub.ObjectValidators
11 import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
18 import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
23 field(:actor, ObjectValidators.ObjectID)
24 # In this case, we save the full object in this activity instead of just a
25 # reference, so we can always see what was actually changed by this.
29 def cast_data(data) do
31 |> cast(data, __schema__(:fields))
34 defp validate_data(cng) do
36 |> validate_required([:id, :type, :actor, :to, :cc, :object])
37 |> validate_inclusion(:type, ["Update"])
38 |> validate_actor_presence()
39 |> validate_updating_rights()
42 def cast_and_validate(data) do
48 # For now we only support updating users, and here the rule is easy:
49 # object id == actor id
50 def validate_updating_rights(cng) do
51 with actor = get_field(cng, :actor),
52 object = get_field(cng, :object),
53 {:ok, object_id} <- ObjectValidators.ObjectID.cast(object),
54 actor_uri <- URI.parse(actor),
55 object_uri <- URI.parse(object_id),
56 true <- actor_uri.host == object_uri.host do
61 |> add_error(:object, "Can't be updated by this actor")