maintenance: dependency upgrade (#81)
[akkoma] / lib / pleroma / web / activity_pub / object_validators / follow_validator.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidator do
6 use Ecto.Schema
7
8 import Ecto.Changeset
9 import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
10
11 @primary_key false
12
13 embedded_schema do
14 quote do
15 unquote do
16 import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
17 message_fields()
18 activity_fields()
19 end
20 end
21
22 field(:state, :string, default: "pending")
23 end
24
25 def cast_data(data) do
26 %__MODULE__{}
27 |> cast(data, __schema__(:fields))
28 end
29
30 defp validate_data(cng) do
31 cng
32 |> validate_required([:id, :type, :actor, :to, :cc, :object])
33 |> validate_inclusion(:type, ["Follow"])
34 |> validate_inclusion(:state, ~w{pending reject accept})
35 |> validate_actor_presence()
36 |> validate_actor_presence(field_name: :object)
37 end
38
39 def cast_and_validate(data) do
40 data
41 |> cast_data
42 |> validate_data
43 end
44 end