logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

question_options_validator.ex (923B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator do
  5. use Ecto.Schema
  6. import Ecto.Changeset
  7. @primary_key false
  8. embedded_schema do
  9. field(:name, :string)
  10. embeds_one :replies, Replies, primary_key: false do
  11. field(:totalItems, :integer)
  12. field(:type, :string)
  13. end
  14. field(:type, :string)
  15. end
  16. def changeset(struct, data) do
  17. struct
  18. |> cast(data, [:name, :type])
  19. |> cast_embed(:replies, with: &replies_changeset/2)
  20. |> validate_inclusion(:type, ["Note"])
  21. |> validate_required([:name, :type])
  22. end
  23. def replies_changeset(struct, data) do
  24. struct
  25. |> cast(data, [:totalItems, :type])
  26. |> validate_inclusion(:type, ["Collection"])
  27. |> validate_required([:type])
  28. end
  29. end