# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnswerValidator do
use Ecto.Schema
+ alias Pleroma.EctoType.ActivityPub.ObjectValidators
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
- alias Pleroma.Web.ActivityPub.ObjectValidators.Types
import Ecto.Changeset
@derive Jason.Encoder
embedded_schema do
- field(:id, Types.ObjectID, primary_key: true)
- field(:to, {:array, :string}, default: [])
- field(:cc, {:array, :string}, default: [])
-
- # is this actually needed?
- field(:bto, {:array, :string}, default: [])
- field(:bcc, {:array, :string}, default: [])
-
+ field(:id, ObjectValidators.ObjectID, primary_key: true)
+ field(:to, ObjectValidators.Recipients, default: [])
+ field(:cc, ObjectValidators.Recipients, default: [])
+ field(:bto, ObjectValidators.Recipients, default: [])
+ field(:bcc, ObjectValidators.Recipients, default: [])
field(:type, :string)
field(:name, :string)
- field(:inReplyTo, :string)
- field(:attributedTo, Types.ObjectID)
- field(:actor, Types.ObjectID)
+ field(:inReplyTo, ObjectValidators.ObjectID)
+ field(:attributedTo, ObjectValidators.ObjectID)
+
+ # TODO: Remove actor on objects
+ field(:actor, ObjectValidators.ObjectID)
end
def cast_and_apply(data) do
def validate_data(data_cng) do
data_cng
|> validate_inclusion(:type, ["Answer"])
- |> validate_required([:id, :inReplyTo, :name])
+ |> validate_required([:id, :inReplyTo, :name, :attributedTo, :actor])
|> CommonValidations.validate_any_presence([:cc, :to])
+ |> CommonValidations.validate_fields_match([:actor, :attributedTo])
|> CommonValidations.validate_actor_presence()
+ |> CommonValidations.validate_host_match()
end
end