Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ID to validation_issue #10521

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not fill the i18n keys correctly, I'm afraid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. the message will look like "The date of birth of [missing 'name' param] is on January 1st"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, actually the same error is there in production as well. Since this is internal to WRT, I thought of adjusting with this error because knowing 'something is wrong' is better than knowing nothing.

TBH I didn't spend time to check if name can be populated here. I guess it should be possible through ticketDetails. I'll explore if that is possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked and WCA ID is available. For now I have added WCA ID. But I feel this fix should be separate PR, I'll do that later. For now I've added it in this PR, will change later.

));
}

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I get what you're going for, and I like the "type safety" kinda idea behind your approach.
However the actual implementation is extremely verbose. Basically you have to spell out a meaningless ValidationIssue::VALIDATION_TYPES every time you build a validation.

(And the "turn the array of keys into a hash that holds its own keys as values" also feels somewhat awkward. Again, I totally get your idea, but the implentation is a bit cumbersome to use)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try consulting ChatGPT (or Copilot or Gemini or whatever) for some ideas?

From the top of my head (haven't thought this through in detail, just spontaneous) you could try passing only the :dob_jan_one constant as a parameter, and have the initialize method in the validation warning check whether that's actually a valid "type". Our test suite would then catch any use-cases with an invalid argument

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with gemini, but didn't get anything good. Your idea actually looks better. I've implemented that now.

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"
gregorbg marked this conversation as resolved.
Show resolved Hide resolved
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, name = nil)

# Check if DOB is January 1
if dob.month == 1 && dob.day == 1
validation_issues << ValidationWarning.new(:persons, competition_id, DOB_0101_WARNING, name: name)
validation_issues << ValidationWarning.new(DOB_JAN_ONE, :persons, competition_id, name: name)
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, name: name)
validation_issues << ValidationWarning.new(DOB_TOO_YOUNG, :persons, competition_id, name: name)
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, name: name)
validation_issues << ValidationWarning.new(DOB_TOO_OLD, :persons, competition_id, name: name)
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)
gregorbg marked this conversation as resolved.
Show resolved Hide resolved
end

def ==(other)
Expand Down
Loading