diff --git a/app/controllers/evaluator_submission_assignments_controller.rb b/app/controllers/evaluator_submission_assignments_controller.rb index a40dd5bf..9d94ecf5 100644 --- a/app/controllers/evaluator_submission_assignments_controller.rb +++ b/app/controllers/evaluator_submission_assignments_controller.rb @@ -4,8 +4,9 @@ class EvaluatorSubmissionAssignmentsController < ApplicationController before_action -> { authorize_user('challenge_manager') } before_action :set_challenge_and_phase - before_action :set_evaluator, only: [:index] + before_action :set_evaluator, only: [:index, :create] before_action :set_assignment, only: [:update] + before_action :set_submission, only: [:create] def index @evaluator_assignments = @phase.evaluator_submission_assignments.includes(:submission).where(user_id: @evaluator.id) @@ -19,6 +20,19 @@ def index @submissions_count = calculate_submissions_count(@assigned_submissions) end + def create + @evaluator_submission_assignment = EvaluatorSubmissionAssignment.new( + user_id: params["evaluator_id"], + submission_id: @submission.id, + status: :assigned + ) + if @evaluator_submission_assignment.save + redirect_to submission_path(@submission), notice: I18n.t("evaluator_submission_assignments.assigned.success") + else + redirect_to submission_path(@submission), notice: I18n.t("evaluator_submission_assignments.assigned.failure") + end + end + # update only the status of the evaluation submission assignment to unassign or reassign an evaluator def update new_status = status_from_params @@ -49,6 +63,10 @@ def set_assignment @assignment = @phase.evaluator_submission_assignments.find(params[:id]) end + def set_submission + @submission = @phase.submissions.find(params[:submission_id]) + end + def status_from_params status = params[:status] || params.dig(:evaluator_submission_assignment, :status) status&.to_sym @@ -68,9 +86,13 @@ def update_assignment_status(new_status) def handle_successful_update(new_status) flash[:success] = t("evaluator_submission_assignments.#{new_status}.success") - respond_to do |format| - format.html { redirect_to_assignment_path } - format.json { render json: { success: true, message: flash[:success] } } + if request&.referer&.include?("submissions") + redirect_to request.referer + else + respond_to do |format| + format.html { redirect_to_assignment_path } + format.json { render json: { success: true, message: flash[:success] } } + end end end diff --git a/app/models/submission.rb b/app/models/submission.rb index 9259d042..b4ce0246 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -83,6 +83,12 @@ class Submission < ApplicationRecord ) } + # Phase evaluators not currently assigned or recused on the submission + def available_evaluators + unavailable_evaluators = evaluators.where.not("evaluator_submission_assignments.status" => "unassigned") + phase.evaluators.where.not(id: unavailable_evaluators) + end + def eligible_for_evaluation? selected? or winner? end diff --git a/app/views/shared/_alert_error.html.erb b/app/views/shared/_alert_error.html.erb index 79653aea..448297e4 100644 --- a/app/views/shared/_alert_error.html.erb +++ b/app/views/shared/_alert_error.html.erb @@ -1,5 +1,5 @@
-
+