Add string length validations to user-input schemas
This commit is contained in:
@@ -21,6 +21,7 @@ defmodule MusicLibrary.OnlineStoreTemplates.OnlineStoreTemplate do
|
||||
|> validate_required([:name, :url_template])
|
||||
|> validate_length(:name, min: 1, max: 100)
|
||||
|> validate_length(:url_template, min: 1, max: 500)
|
||||
|> validate_length(:description, max: 1000)
|
||||
|> validate_url_template()
|
||||
end
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ defmodule MusicLibrary.RecordSets.RecordSet do
|
||||
record_set
|
||||
|> cast(attrs, [:name, :description])
|
||||
|> validate_required([:name])
|
||||
|> validate_length(:name, min: 1, max: 100)
|
||||
|> validate_length(:description, max: 10_000)
|
||||
end
|
||||
|
||||
def count_by_status(record_set) do
|
||||
|
||||
@@ -29,6 +29,8 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRule do
|
||||
scrobble_rule
|
||||
|> cast(attrs, [:type, :match_value, :target_musicbrainz_id, :enabled, :description])
|
||||
|> validate_required([:type, :match_value, :target_musicbrainz_id])
|
||||
|> validate_length(:match_value, min: 1, max: 500)
|
||||
|> validate_length(:description, max: 1000)
|
||||
|> unique_constraint([:type, :match_value], error_key: :match_value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,5 +14,6 @@ defmodule MusicLibrary.Secrets.Secret do
|
||||
secret
|
||||
|> cast(attrs, [:name, :value])
|
||||
|> validate_required([:name, :value])
|
||||
|> validate_length(:name, min: 1, max: 100)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user