2020-06-11 18:23:10 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-06-11 18:23:10 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator do
|
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
import Ecto.Changeset
|
|
|
|
|
|
|
|
@primary_key false
|
|
|
|
|
|
|
|
embedded_schema do
|
|
|
|
field(:name, :string)
|
2020-06-12 19:22:05 +00:00
|
|
|
|
2020-06-14 20:25:04 +00:00
|
|
|
embeds_one :replies, Replies, primary_key: false do
|
2020-06-12 19:22:05 +00:00
|
|
|
field(:totalItems, :integer)
|
|
|
|
field(:type, :string)
|
|
|
|
end
|
|
|
|
|
2020-06-11 18:23:10 +00:00
|
|
|
field(:type, :string)
|
|
|
|
end
|
|
|
|
|
|
|
|
def changeset(struct, data) do
|
|
|
|
struct
|
|
|
|
|> cast(data, [:name, :type])
|
2020-06-12 19:22:05 +00:00
|
|
|
|> cast_embed(:replies, with: &replies_changeset/2)
|
2020-06-11 18:23:10 +00:00
|
|
|
|> validate_inclusion(:type, ["Note"])
|
|
|
|
|> validate_required([:name, :type])
|
|
|
|
end
|
|
|
|
|
2020-06-12 19:22:05 +00:00
|
|
|
def replies_changeset(struct, data) do
|
2020-06-11 18:23:10 +00:00
|
|
|
struct
|
2020-06-12 19:22:05 +00:00
|
|
|
|> cast(data, [:totalItems, :type])
|
2020-06-11 18:23:10 +00:00
|
|
|
|> validate_inclusion(:type, ["Collection"])
|
|
|
|
|> validate_required([:type])
|
|
|
|
end
|
|
|
|
end
|