Skip to content

Commit

Permalink
add reviewers to students in multiple sections
Browse files Browse the repository at this point in the history
Students who are enrolled in multiple course sections can now have
reviewers added to them without causing a canvas error.  This change
also includes a fix to make the moderation page render properly when a
student has no grades awaiting moderation.

fixes CNVS-27153
fixes CNVS-28190

test plan:
 - Create an course with multiple sections.
 - Enroll a student in more than one section.
 - Create an assignment that allows for moderation.
 - Go into the moderation panel and add a reviewer for all students.
 - Note that reviewers are added with no error.
 - Note that the final grade column is a -

Change-Id: I77cf50c5928b3f947a580ce4db6e0fc01ea569ef
Reviewed-on: https://gerrit.instructure.com/75035
Reviewed-by: Spencer Olson <[email protected]>
Reviewed-by: Derek Bender <[email protected]>
Tested-by: Jenkins
QA-Review: Adrian Russell <[email protected]>
Product-Review: Keith T. Garner <[email protected]>
  • Loading branch information
ktgeek authored and roor0 committed Mar 23, 2016
1 parent 92913ef commit 1b8c16b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/controllers/moderation_set_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def create
new_student_ids = params[:student_ids].map(&:to_i) - current_selections

students = @context.students_visible_to(@current_user, include: :inactive).
where(id: new_student_ids).to_a
where(id: new_student_ids).uniq.to_a

students.each do |student|
@assignment.moderated_grading_selections.create! student: student
end
Expand Down
14 changes: 8 additions & 6 deletions app/jsx/assignments/ModeratedStudentList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ define([
},

renderFinalGrade (student) {
if (student.selected_provisional_grade_id || (student.provisional_grades && student.provisional_grades.length < 2)) {
var grade = _.find(student.provisional_grades, (pg) => {
return pg.provisional_grade_id === student.selected_provisional_grade_id;
});
if (student.selected_provisional_grade_id || (student.provisional_grades && student.provisional_grades.length === 1)) {
var grade;
// If they only have one provisional grade show that as the grade
if (student.provisional_grades.length < 2) {
grade = student.provisional_grades[0]
if (student.provisional_grades.length === 1) {
grade = student.provisional_grades[0];
} else {
grade = _.find(student.provisional_grades, (pg) => {
return pg.provisional_grade_id === student.selected_provisional_grade_id;
});
}
return (
<div className='col-xs-2' role="gridcell">
Expand Down
19 changes: 18 additions & 1 deletion spec/apis/v1/moderation_set_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
describe 'Moderated Grades API', type: :request do
before :once do
course_with_teacher_logged_in active_all: true
sec1 = @course.course_sections.create!(:name => "section 1")
sec2 = @course.course_sections.create!(:name => "section 2")
@assignment = @course.assignments.create! name: "asdf"
@assignment.update_attribute :moderated_grading, true
@student1, @student2 = n_students_in_course(2)
@student1, @student2, @student3 = n_students_in_course(3)
@course.enroll_student(@student1, :section => sec1, :allow_multiple_enrollments => true)
@course.enroll_student(@student2, :section => sec1, :allow_multiple_enrollments => true)
@course.enroll_student(@student3, :section => sec1, :allow_multiple_enrollments => true)
@course.enroll_student(@student3, :section => sec2, :allow_multiple_enrollments => true)
@user = @teacher
@assignment.moderated_grading_selections.create! student: @student1
end
Expand Down Expand Up @@ -75,6 +81,17 @@
expect(json.first["id"]).to eq @student2.id
end

it "creates a single selection for students in multiple sections" do
json = api_call :post,
"/api/v1/courses/#{@course.id}/assignments/#{@assignment.id}/moderated_students",
{controller: 'moderation_set', action: 'create',
format: 'json', course_id: @course.id, assignment_id: @assignment.id},
student_ids: [@student3.id]

expect(json.size).to eq 1
expect(json.first["id"]).to eq @student3.id
end

it 'requires moderate_grades permissions' do
@user = @student1
raw_api_call :post,
Expand Down
28 changes: 28 additions & 0 deletions spec/coffeescripts/jsx/assignments/ModeratedStudentListSpec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ define [
}
]
}
fakeUngradedStudentList = {students:
[
{
'id': 3
'display_name': '[email protected]'
'avatar_image_url': 'https://canvas.instructure.com/images/messages/avatar-50.png'
'html_url': 'http://localhost:3000/courses/1/users/3'
'in_moderation_set': false
'selected_provisional_grade_id': null
}
]
}

module 'ModeratedStudentList'

Expand Down Expand Up @@ -97,6 +109,22 @@ define [
equal gradeColumns[0].props.children[1].props.children, 4
React.unmountComponentAtNode(studentList.getDOMNode().parentNode)

test 'properly renders final grade if there are no provisional grades', ->
newFakeStudentList = _.extend({}, fakeUngradedStudentList)
studentList = TestUtils.renderIntoDocument(React.createElement(ModeratedStudentList,
urls: {assignment_speedgrader_url: 'blah'},
includeModerationSetColumns: true,
studentList: newFakeStudentList,
assignment: {published: false},
handleCheckbox: () => 'stub'
onSelectProvisionalGrade: () => 'stub'
)
)

gradeColumns = TestUtils.scryRenderedDOMComponentsWithClass(studentList, 'AssignmentList_Grade')
equal gradeColumns[0].getDOMNode().querySelectorAll('span')[1].textContent, '-', 'grade column is a dash'
React.unmountComponentAtNode(studentList.getDOMNode().parentNode)

test 'does not show radio button if there is only one provisional grade', ->
newFakeStudentList = _.extend({}, fakeStudentList)
studentList = TestUtils.renderIntoDocument(React.createElement(ModeratedStudentList,
Expand Down

0 comments on commit 1b8c16b

Please sign in to comment.