Skip to content

Commit

Permalink
Add ID to validation_issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljames-dj committed Jan 13, 2025
1 parent 12c33cb commit 27e3754
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ticketStatuses } from '../../../lib/wca-data.js.erb';
import Loading from '../../Requests/Loading';
import useLoadedData from '../../../lib/hooks/useLoadedData';
import Errored from '../../Requests/Errored';
import I18n from '../../../lib/i18n';

function EditPersonValidations({ ticketDetails }) {
const { ticket } = ticketDetails;
Expand All @@ -18,7 +19,7 @@ function EditPersonValidations({ ticketDetails }) {
if (error) return <Errored />;

return validators.dob.map((validator) => (
<Message warning>{validator.message}</Message>
<Message warning>{I18n.t(`validators.person.${validator.id}`)}</Message>
));
}

Expand Down
1 change: 1 addition & 0 deletions config/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ translations:
- "*.time_limit.*"
- "*.users.edit.*"
- "*.persons.index.*"
- "*.validators.*"
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2806,3 +2806,8 @@ en:
description_html: "On this page we offer the WST developer export for download as SQL dump. Details can be found at %{github_link}."
#context: The button that is clicked to download the file
download: "Download"
validators:
person:
dob_jan_one: "The date of birth of %{name} is on January 1st, please ensure it's correct."
dob_too_young: "%{name} seems to be less than 3 years old, please ensure it's correct."
dob_too_old: "%{name} seems to be around 100 years old, please ensure it's correct."
12 changes: 6 additions & 6 deletions lib/results_validators/persons_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class PersonsValidator < GenericValidator
WHITESPACE_IN_NAME_ERROR = "Person '%{name}' has leading/trailing whitespaces or double whitespaces."
WRONG_WCA_ID_ERROR = "Person %{name} has a WCA ID which does not exist: %{wca_id}."
WRONG_PARENTHESIS_FORMAT_ERROR = "Opening parenthesis in '%{name}' must be preceded by a space."
DOB_0101_WARNING = "The date of birth of %{name} is on January 1st, please ensure it's correct."
VERY_YOUNG_PERSON_WARNING = "%{name} seems to be less than 3 years old, please ensure it's correct."
NOT_SO_YOUNG_PERSON_WARNING = "%{name} seems to be around 100 years old, please ensure it's correct."
DOB_JAN_ONE = "dob_jan_one"
DOB_TOO_YOUNG = "dob_too_young"
DOB_TOO_OLD = "dob_too_old"
SAME_PERSON_NAME_WARNING = "There is already at least one person with the name '%{name}' in the WCA database (%{wca_ids}). " \
"Please ensure that your '%{name}' is a different person. If not, please assign the correct WCA ID to the user account and regenerate the results JSON."
NON_MATCHING_DOB_WARNING = "The birthdate '%{dob}' provided for %{name} (%{wca_id}) does not match the current record in the WCA database ('%{expected_dob}'). If this is an error, fix it. Otherwise, leave a comment to the WRT about it."
Expand Down Expand Up @@ -46,17 +46,17 @@ def self.dob_validations(dob, competition_id = nil, **message_args)

# Check if DOB is January 1
if dob.month == 1 && dob.day == 1
validation_issues << ValidationWarning.new(:persons, competition_id, DOB_0101_WARNING, **message_args)
validation_issues << ValidationWarning.new(DOB_JAN_ONE, :persons, competition_id, **message_args)
end

# Check if DOB is very young, competitor less than 3 years old are extremely rare, so we'd better check these birthdate are correct.
if dob.year >= Time.now.year - 3
validation_issues << ValidationWarning.new(:persons, competition_id, VERY_YOUNG_PERSON_WARNING, **message_args)
validation_issues << ValidationWarning.new(DOB_TOO_YOUNG, :persons, competition_id, **message_args)
end

# Check if DOB is not so young
if dob.year <= Time.now.year - 100
validation_issues << ValidationWarning.new(:persons, competition_id, NOT_SO_YOUNG_PERSON_WARNING, **message_args)
validation_issues << ValidationWarning.new(DOB_TOO_OLD, :persons, competition_id, **message_args)
end

validation_issues
Expand Down
6 changes: 3 additions & 3 deletions lib/results_validators/validation_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
module ResultsValidators
class ValidationIssue
attr_reader :kind, :competition_id
def initialize(kind, competition_id, message, **message_args)
@message = message
def initialize(id, kind, competition_id, **message_args)
@id = id
@kind = kind
@args = message_args
@competition_id = competition_id
end

def to_s
format(@message, @args)
I18n.t("validators.person.#{@id}", @args)
end

def ==(other)
Expand Down

0 comments on commit 27e3754

Please sign in to comment.