Add some backend changes and validation for field length

Closes #225 and #226

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-10-18 11:21:31 +02:00
parent 90ba211c90
commit 342506bac0
4 changed files with 103 additions and 5 deletions

View File

@@ -125,6 +125,7 @@ defmodule Mobilizon.Events.Event do
|> cast(attrs, @attrs)
|> cast_embed(:options)
|> validate_required(@required_attrs)
|> validate_lengths()
end
@doc false
@@ -135,6 +136,18 @@ defmodule Mobilizon.Events.Event do
|> cast_embed(:options)
|> put_tags(attrs)
|> validate_required(@update_required_attrs)
|> validate_lengths()
end
@spec validate_lengths(Ecto.Changeset.t()) :: Ecto.Changeset.t()
defp validate_lengths(%Ecto.Changeset{} = changeset) do
changeset
|> validate_length(:title, min: 3, max: 200)
|> validate_length(:online_address, min: 3, max: 2000)
|> validate_length(:phone_address, min: 3, max: 200)
|> validate_length(:category, min: 2, max: 100)
# |> validate_length(:category, min: 2, max: 100)
|> validate_length(:slug, min: 3, max: 200)
end
@doc """