diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b3fe4f47..59eddaf7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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? diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 83d6ebe7..2e500353 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index da5c2e42..342abd68 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/es.yml b/config/locales/es.yml index 2e6c4ea8..7dc38851 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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 diff --git a/decidim-age_action_authorization/lib/decidim/age_action_authorization/authorizer.rb b/decidim-age_action_authorization/lib/decidim/age_action_authorization/authorizer.rb index 232335d0..ba8c36a1 100644 --- a/decidim-age_action_authorization/lib/decidim/age_action_authorization/authorizer.rb +++ b/decidim-age_action_authorization/lib/decidim/age_action_authorization/authorizer.rb @@ -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) @@ -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