Skip to content

Commit

Permalink
Include the validator warnings in the mail to WRT
Browse files Browse the repository at this point in the history
  • Loading branch information
viroulep committed Jan 13, 2019
1 parent 3840fb5 commit 941856e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion WcaOnRails/app/controllers/results_submission_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion WcaOnRails/app/models/results_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions WcaOnRails/app/views/competitions_mailer/results_submitted.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</p>

<p>
<% 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? %>
<br/>Warnings detected in <%= type %>
<ul>
<% warnings.each do |warning| %>
<li><%= warning %></li>
<% end %>
</ul>
<% end %>
<% end %>
<% end %>
</p>

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

<blockquote><%= md @results_submission.message %></blockquote>

0 comments on commit 941856e

Please sign in to comment.