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 bbd1b25cc2..2f80fb9b96 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 @@ -8,11 +8,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator do import Ecto.Changeset alias Pleroma.EctoType.ActivityPub.ObjectValidators + alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes @primary_key false embedded_schema do field(:name, :string) + field(:nameRendered, :string) field(:nameMap, ObjectValidators.MapOfString) embeds_one :replies, Replies, primary_key: false do @@ -23,9 +25,17 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator do field(:type, :string, default: "Note") end + defp fix(data) do + data + # name is used in Answers, so better not change it + |> CommonFixes.fix_multilang_field("nameRendered", "nameMap", multiline: false) + end + def changeset(struct, data) do + data = fix(data) + struct - |> cast(data, [:name, :nameMap, :type]) + |> cast(data, [:name, :nameRendered, :nameMap, :type]) |> cast_embed(:replies, with: &replies_changeset/2) |> validate_inclusion(:type, ["Note"]) |> validate_required([:name, :type]) diff --git a/test/pleroma/web/activity_pub/object_validators/question_options_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/question_options_validator_test.exs index 87a0bafa07..a45c205cf8 100644 --- a/test/pleroma/web/activity_pub/object_validators/question_options_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/question_options_validator_test.exs @@ -20,7 +20,7 @@ test "" do "nameMap" => name_map } - assert %{valid?: true, changes: %{nameMap: ^name_map}} = + assert %{valid?: true, changes: %{nameMap: ^name_map, nameRendered: _}} = QuestionOptionsValidator.changeset(%QuestionOptionsValidator{}, data) end end