From 941856e6e6e2a9a8a4615b18284e8008fd97729d Mon Sep 17 00:00:00 2001 From: Philippe Virouleau Date: Sun, 16 Dec 2018 16:03:07 +0100 Subject: [PATCH] Include the validator warnings in the mail to WRT --- .../results_submission_controller.rb | 3 ++- WcaOnRails/app/models/results_submission.rb | 5 ++++- .../competitions_mailer/results_submitted.erb | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/WcaOnRails/app/controllers/results_submission_controller.rb b/WcaOnRails/app/controllers/results_submission_controller.rb index 009246f1d53..0bca687fd19 100644 --- a/WcaOnRails/app/controllers/results_submission_controller.rb +++ b/WcaOnRails/app/controllers/results_submission_controller.rb @@ -48,7 +48,8 @@ def create @competition.update!(results_submitted_at: Time.now) redirect_to competition_path(@competition) else - @results_validator = CompetitionResultsValidator.new(@competition.id) + flash[:danger] = "Submitted results contain errors." + @results_validator = @results_submission.results_validator render :new end end diff --git a/WcaOnRails/app/models/results_submission.rb b/WcaOnRails/app/models/results_submission.rb index d41a2c28727..968e853fea8 100644 --- a/WcaOnRails/app/models/results_submission.rb +++ b/WcaOnRails/app/models/results_submission.rb @@ -12,13 +12,16 @@ class ResultsSubmission validates :schedule_url, presence: true, url: true validate do - results_validator = CompetitionResultsValidator.new(competition_id) if results_validator.total_errors != 0 # this shouldn't actually happen through a "normal" usage of the website errors.add(:message, "submitted results contain errors") end end + def results_validator + @results_validator ||= CompetitionResultsValidator.new(competition_id) + end + # FIXME: what is this used for? def ==(other) self.class == other.class && self.state == other.state diff --git a/WcaOnRails/app/views/competitions_mailer/results_submitted.erb b/WcaOnRails/app/views/competitions_mailer/results_submitted.erb index eda51d70388..94b62dc5cf7 100644 --- a/WcaOnRails/app/views/competitions_mailer/results_submitted.erb +++ b/WcaOnRails/app/views/competitions_mailer/results_submitted.erb @@ -17,6 +17,24 @@ The Delegate has confirmed the competition's events page and the competition's schedule page reflect what happened during the competition.

+

+ <% if @results_submission.results_validator.total_warnings == 0 %> + The competition results had no warning. + <% else %> + Please find below the list of warnings for the competition's results: + <% @results_submission.results_validator.warnings.each do |type, warnings| %> + <% if warnings.any? %> +
Warnings detected in <%= type %> +

+ <% end %> + <% end %> + <% end %> +

+

Here's a message from <%= @submitter_user.name %>:

<%= md @results_submission.message %>