Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def text_invalid_age_authorizer(status)
min_age = options["age"]
max_age = options["max_age"]

return t("corrupted_metadata", scope:) if status.instance_variable_get(:@authorization_handler).instance_variable_get(:@action_authorizer).missing_fields.present?

if min_age.present? && max_age.present?
t("both", scope:, max_age:, min_age:)
elsif min_age.present? && max_age.blank?
Expand Down
3 changes: 3 additions & 0 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ ca:
invalid_field:
both: Acció restringida als habitants del padró municipal entre %{min_age}
i %{max_age} anys
corrupted_metadata: No s'han pogut recuperar les dades necessàries per
verificar-ne l'edat. Torneu a obtenir l'autorització del padró municipal
per poder verificar les vostres dades.
max_age: Acció restringida als habitants del padró municipal menors
de %{max_age} anys
min_age: Acció restringida als habitants del padró municipal majors
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ en:
invalid_field:
both: Action restricted to the inhabitants of the municipal census between
%{min_age} and %{max_age} years old.
corrupted_metadata: The data required to verify your age could not be
retrieved. Please obtain authorization of the municipal census again
to verify your data.
max_age: Action restricted to the inhabitants of the municipal census
under the age of %{max_age}.
min_age: Action restricted to the inhabitants of the municipal census
Expand Down
3 changes: 3 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ es:
invalid_field:
both: Acción restringida a los habitantes del padrón municipal entre
%{min_age} y %{max_age} años
corrupted_metadata: No se han podido recuperar los datos necesarios
para verificar tu edad. Vuelve a obtener la autorización del padrón
municipal para poder verificar tus datos.
max_age: Acción restringida a los habitantes del padrón municipal menores
de %{max_age} años
min_age: Acción restringida a los habitantes del padrón municipal mayores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ def set_unmatched_fields

def valid_metadata?
return unless authorization
return true if authorization.metadata["birthdate"].blank?

!authorization.metadata["birthdate"].nil?
birthdate.present?
end

def valid_age?
return false if birthdate.blank?

min_date = birthdate + minimum_age.years
max_date = options["max_age"].present? &&
(birthdate + options["max_age"].to_i.years)
Expand All @@ -38,7 +41,7 @@ def valid_age?
end

def birthdate
@birthdate ||= Date.strptime(authorization.metadata["birthdate"], "%Y/%m/%d")
@birthdate ||= Date._strptime(authorization.metadata["birthdate"], "%Y/%m/%d").present? ? Date.strptime(authorization.metadata["birthdate"], "%Y/%m/%d") : nil
end

def minimum_age
Expand Down