publish selected provisional grades

test plan:
 - have a moderated assignment and add some users to moderation
   (leave some users out of the moderation set)
 - as two separate TAs, create provisional grades
   for the students in the moderation set
 - also create one provisional grade for each student that
   is not in the moderation set (eventually speedgrader will
   prevent you from creating more than one)
 - as a moderator, select provisional grades on the moderation
   page
 - ensure that the correct provisional grades are published:
   - for students in the moderation set, the grade selected
     by radio button
   - for students not in the moderation set, the one and only
     provisional grade

fixes CNVS-23036

Change-Id: Icf0919d65648e48e31322e09318bff00a1e98949
Reviewed-on: https://gerrit.instructure.com/63313
Tested-by: Jenkins
Reviewed-by: Dan Minkevitch <dan@instructure.com>
Reviewed-by: James Williams  <jamesw@instructure.com>
QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2015-09-15 11:10:26 -06:00
parent 8e76ab59e1
commit 4a078f97b0
2 changed files with 32 additions and 8 deletions

View File

@ -671,9 +671,7 @@ class SubmissionsApiController < ApplicationController
# Use the "Select provisional grade" endpoint to choose which provisional grade to publish
# for a particular submission.
#
# NOTE: The preceding paragraph is a lie, because provisional grade selection is not yet implemented.
# What will _actually_ happen is, we'll publish the first provisional grade for the submission
# (by graded_at date).
# Students not in the moderation set will have their one and only provisional grade published.
#
# WARNING: This is irreversible. This will overwrite any existing grades in the gradebook.
#
@ -694,12 +692,20 @@ class SubmissionsApiController < ApplicationController
submissions = @assignment.submissions.preload(:all_submission_comments,
{ :provisional_grades => :rubric_assessments })
selections = @assignment.moderated_grading_selections.index_by(&:student_id)
submissions.each do |submission|
# TODO M2 use an actual selection instead of just picking the first one
selected_provisional_grade = submission.provisional_grades
.select { |pg| pg.graded_at.present? }
.sort_by { |pg| pg.graded_at }
.first
if (selection = selections[submission.user_id])
# student in moderation: choose the selected provisional grade
selected_provisional_grade = submission.provisional_grades
.detect { |pg| pg.id == selection.selected_provisional_grade_id }
else
# student not in moderation: choose the first one with a grade (there should only be one)
selected_provisional_grade = submission.provisional_grades
.select { |pg| pg.graded_at.present? }
.sort_by { |pg| pg.created_at }
.first
end
if selected_provisional_grade
selected_provisional_grade.publish!
end

View File

@ -3294,6 +3294,24 @@ describe 'Submissions API', type: :request do
@student.reload
expect(@student.messages.map(&:notification_name)).to be_include 'Submission Graded'
end
it "publishes the selected provisional grade when the student is in the moderation set" do
@submission.provisional_grade(@ta).update_attribute(:graded_at, 1.minute.ago)
@other_ta = user :active_user => true
@course.enroll_ta @other_ta, :enrollment_state => 'active'
@assignment.grade_student(@student, { :grader => @other_ta, :score => 90, :provisional => true })
sel = @assignment.moderated_grading_selections.build
sel.student_id = @student.id
sel.selected_provisional_grade_id = @submission.provisional_grade(@other_ta).id
sel.save!
api_call_as_user(@teacher, :post, @path, @params)
expect(@submission.reload.workflow_state).to eq 'graded'
expect(@submission.grader).to eq @other_ta
expect(@submission.score).to eq 90
end
end
end
end