Convert nameMap in question options
This commit is contained in:
parent
5c62c50e9b
commit
4cfd7b4f79
2 changed files with 12 additions and 2 deletions
|
@ -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])
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue