Skip to content

Commit abdac08

Browse files
Generate an error message when birthdate cannot be extracted from authorization metadata
1 parent a901cec commit abdac08

5 files changed

Lines changed: 16 additions & 2 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def text_invalid_age_authorizer(status)
99
min_age = options["age"]
1010
max_age = options["max_age"]
1111

12+
return t("corrupted_metadata", scope:) if status.instance_variable_get(:@authorization_handler).instance_variable_get(:@action_authorizer).missing_fields.present?
13+
1214
if min_age.present? && max_age.present?
1315
t("both", scope:, max_age:, min_age:)
1416
elsif min_age.present? && max_age.blank?

config/locales/ca.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ ca:
9292
invalid_field:
9393
both: Acció restringida als habitants del padró municipal entre %{min_age}
9494
i %{max_age} anys
95+
corrupted_metadata: No s'han pogut recuperar les dades necessàries per
96+
verificar-ne l'edat. Torneu a obtenir l'autorització del padró municipal
97+
per poder verificar les vostres dades.
9598
max_age: Acció restringida als habitants del padró municipal menors
9699
de %{max_age} anys
97100
min_age: Acció restringida als habitants del padró municipal majors

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ en:
7575
invalid_field:
7676
both: Action restricted to the inhabitants of the municipal census between
7777
%{min_age} and %{max_age} years old.
78+
corrupted_metadata: The data required to verify your age could not be
79+
retrieved. Please obtain authorization of the municipal census again
80+
to verify your data.
7881
max_age: Action restricted to the inhabitants of the municipal census
7982
under the age of %{max_age}.
8083
min_age: Action restricted to the inhabitants of the municipal census

config/locales/es.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ es:
7575
invalid_field:
7676
both: Acción restringida a los habitantes del padrón municipal entre
7777
%{min_age} y %{max_age} años
78+
corrupted_metadata: No se han podido recuperar los datos necesarios
79+
para verificar tu edad. Vuelve a obtener la autorización del padrón
80+
municipal para poder verificar tus datos.
7881
max_age: Acción restringida a los habitantes del padrón municipal menores
7982
de %{max_age} años
8083
min_age: Acción restringida a los habitantes del padrón municipal mayores

decidim-age_action_authorization/lib/decidim/age_action_authorization/authorizer.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ def set_unmatched_fields
2121

2222
def valid_metadata?
2323
return unless authorization
24+
return true if authorization.metadata["birthdate"].blank?
2425

25-
!authorization.metadata["birthdate"].nil?
26+
birthdate.present?
2627
end
2728

2829
def valid_age?
30+
return false if birthdate.blank?
31+
2932
min_date = birthdate + minimum_age.years
3033
max_date = options["max_age"].present? &&
3134
(birthdate + options["max_age"].to_i.years)
@@ -38,7 +41,7 @@ def valid_age?
3841
end
3942

4043
def birthdate
41-
@birthdate ||= Date.strptime(authorization.metadata["birthdate"], "%Y/%m/%d")
44+
@birthdate ||= Date._strptime(authorization.metadata["birthdate"], "%Y/%m/%d").present? ? Date.strptime(authorization.metadata["birthdate"], "%Y/%m/%d") : nil
4245
end
4346

4447
def minimum_age

0 commit comments

Comments
 (0)