aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2020-06-12 21:22:05 +0200
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>2020-07-15 11:39:54 +0200
commit89a2433154b05c378f9c5b3224375049f3dbc8af (patch)
tree7af9826cd1be59f623d9fded3f4c35122c8b3954
parentc5efaf6b00bf582a6eef7b5728fe5042f5fcc702 (diff)
downloadpleroma-89a2433154b05c378f9c5b3224375049f3dbc8af.tar.gz
QuestionOptionsValidator: inline schema for replies
-rw-r--r--lib/pleroma/web/activity_pub/object_validators/question_options_validator.ex28
1 files changed, 9 insertions, 19 deletions
diff --git a/lib/pleroma/web/activity_pub/object_validators/question_options_validator.ex b/lib/pleroma/web/activity_pub/object_validators/question_options_validator.ex
index 9bc7e0cc0..8291d7b9f 100644
--- a/lib/pleroma/web/activity_pub/object_validators/question_options_validator.ex
+++ b/lib/pleroma/web/activity_pub/object_validators/question_options_validator.ex
@@ -5,42 +5,32 @@
defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator do
use Ecto.Schema
- alias Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsRepliesValidator
-
import Ecto.Changeset
@primary_key false
embedded_schema do
field(:name, :string)
- embeds_one(:replies, QuestionOptionsRepliesValidator)
+
+ embeds_one :replies, Replies do
+ field(:totalItems, :integer)
+ field(:type, :string)
+ end
+
field(:type, :string)
end
def changeset(struct, data) do
struct
|> cast(data, [:name, :type])
- |> cast_embed(:replies)
+ |> cast_embed(:replies, with: &replies_changeset/2)
|> validate_inclusion(:type, ["Note"])
|> validate_required([:name, :type])
end
-end
-
-defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsRepliesValidator do
- use Ecto.Schema
-
- import Ecto.Changeset
- @primary_key false
-
- embedded_schema do
- field(:totalItems, :integer)
- field(:type, :string)
- end
-
- def changeset(struct, data) do
+ def replies_changeset(struct, data) do
struct
- |> cast(data, __schema__(:fields))
+ |> cast(data, [:totalItems, :type])
|> validate_inclusion(:type, ["Collection"])
|> validate_required([:type])
end