Skip to content

Commit

Permalink
Merge pull request #433 from GSA/419/prevent-selected-evaluation-revi…
Browse files Browse the repository at this point in the history
…sions

[419] Submission selected to advance can not be updated by a challenge manager
  • Loading branch information
stepchud authored Feb 20, 2025
2 parents e724f9c + 0f65289 commit 6a8d9c1
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 146 deletions.
4 changes: 2 additions & 2 deletions app/controllers/evaluation_overrides_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EvaluationOverridesController < ApplicationController
def show; end

def update
if @evaluation.update(evaluation_params)
if @evaluation.revisable? && @evaluation.update(evaluation_params)
redirect_to @return_path, notice: I18n.t("evaluation_overrides.notices.submitted")
else
render :show, status: :unprocessable_entity
Expand All @@ -32,7 +32,7 @@ def ensure_evaluation_completed_and_authorized
return if @evaluation.completed_at.present? &&
current_user.challenge_manager_challenges.exists?(id: @evaluation.submission.challenge_id)

redirect_to @return_path, alert: I18n.t("evaluation_overrides.alerts.unauthorized")
redirect_to @return_path, alert: I18n.t("evaluation_overrides.alerts.not_found")
end

def evaluation_params
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/evaluations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def average_score(submission)
where(evaluator_submission_assignment: assigned_evaluations).
where.not(completed_at: nil)

unless completed_evaluations.count == assigned_evaluations.count
if completed_evaluations.count != assigned_evaluations.count
return Score.new(0, "0", "N/A")
end

avg = completed_evaluations.average(:total_score)
score = avg ? avg.round : 0
score = avg ? avg.round(2) : 0
Score.new(score, score.to_s, score.to_s)
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def calculated_total_score(use_evaluator_scores: false)
format_total(total)
end

def revisable?
submission.selected?
end

def revised?
evaluation_scores.any? { |score| score.score_override.present? }
end
Expand Down
23 changes: 13 additions & 10 deletions app/views/evaluation_overrides/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
<% end %>

<% disabled = form_disabled?(@evaluation) %>
<% disabled = !@evaluation.revisable? %>

<%= hidden_field_tag :authenticity_token, form_authenticity_token %>

Expand Down Expand Up @@ -62,15 +62,15 @@
<p><%= "#{criterion.description} (#{criterion.points_or_weight} points)" %></p>

<div class="usa-form-group">
<%= evaluation_score_input(score_fields, :score_override, criterion, rand, false) %>
<%= evaluation_score_input(score_fields, :score_override, criterion, rand, disabled) %>

<%= inline_error(score_fields, :score_override, rand) %>
</div>

<div>
<p>Evaluator Feedback:</p>

<%= score_fields.object.comment || "N/A" %>
<%= score_fields.object.comment.presence || "N/A" %>
</div>

<div class="usa-form-group">
Expand All @@ -85,7 +85,7 @@
maxlength: 3000,
rows: 7,
class: "usa-textarea usa-character-count__field #{input_error_class(score_fields, :comment_override)}",
data: {"action": "form-validation#validatePresence focusout->form-validation#validatePresence"}
disabled:
%>

<span class="usa-character-count__message"></span>
Expand Down Expand Up @@ -114,7 +114,7 @@
maxlength: 3000,
rows: "7",
class: "usa-textarea #{input_error_class(form, :additional_comments)}",
disabled: %>
disabled: true %>
</div>
</div>
</div>
Expand All @@ -134,18 +134,21 @@
<%= form.text_area :revision_comments,
maxlength: 3000,
rows: "7",
class: "usa-textarea #{input_error_class(form, :revision_comments)}"
class: "usa-textarea #{input_error_class(form, :revision_comments)}",
disabled:
%>

<%= inline_error(form, :revision_comments, rand) %>
</div>
</div>
</div>

<div class="display-flex flex-justify-center">
<%= link_to "Cancel", "#", class: "usa-button usa-button--outline", data: {"action": "modal#open", "modal-target-id": "cancel"} %>
<%= form.button "Revise Evaluation", class: "usa-button", data: {"action": "modal#open", "modal-target-id": "revise"} %>
</div>
<% if !disabled %>
<div class="display-flex flex-justify-center">
<%= link_to "Cancel", "#", class: "usa-button usa-button--outline", data: {"action": "modal#open", "modal-target-id": "cancel"} %>
<%= form.button "Revise Evaluation", class: "usa-button", data: {"action": "modal#open", "modal-target-id": "revise"} %>
</div>
<% end %>

<%= render "modals/confirmation",
id: "cancel",
Expand Down
2 changes: 1 addition & 1 deletion app/views/evaluations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
maxlength: 3000,
rows: 7,
class: "usa-textarea usa-character-count__field #{input_error_class(score_fields, :comment)}",
data: {"action": "form-validation#validatePresence focusout->form-validation#validatePresence"},
data: @evaluation.evaluation_form.comments_required? ? {"action": "form-validation#validatePresence focusout->form-validation#validatePresence"} : nil,
disabled: %>

<span class="usa-character-count__message"></span>
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/evaluations_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@
completed_at: Time.current
)

average_score = (evaluation1.total_score + evaluation2.total_score) / 2
average_score = average_score ? average_score.round : 0
average_score = (evaluation1.total_score.to_f + evaluation2.total_score) / 2
average_score = average_score ? average_score.round(2) : 0

result = helper.average_score(submission)
expect(result.raw_score).to eq(average_score)
Expand Down
Loading

0 comments on commit 6a8d9c1

Please sign in to comment.