don't allow setting assignment or group positions to nil

also fix the grade summary page if any existing rows
have null positions

test plan:
* use the assignments API to try to update an assignment
 to have a blank/null position
* it should not save the change

closes #LA-139

Change-Id: I9a3e26a41dad328defa763c5f9c8f9697ed5a4c5
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/216204
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Tested-by: Jenkins
QA-Review: Jeremy Stanley <jeremy@instructure.com>
Product-Review: James Williams <jamesw@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
James Williams 2019-11-06 13:44:39 -07:00
parent 17cb63df31
commit 61c6a42125
4 changed files with 11 additions and 1 deletions

View File

@ -873,6 +873,7 @@ class Assignment < ActiveRecord::Base
self.title ||= (self.assignment_group.default_assignment_name rescue nil) || "Assignment"
self.infer_all_day
self.position = self.position_was if self.will_save_change_to_position? && self.position.nil? # don't allow setting to nil
if !self.assignment_group || (self.assignment_group.deleted? && !self.deleted?)
ensure_assignment_group(false)

View File

@ -67,6 +67,7 @@ class AssignmentGroup < ActiveRecord::Base
end
self.default_assignment_name = self.name
self.default_assignment_name = self.default_assignment_name.singularize if I18n.locale == :en
self.position = self.position_was if self.will_save_change_to_position? && self.position.nil? # don't allow setting to nil
end
protected :generate_default_values

View File

@ -169,7 +169,7 @@ class GradeSummaryPresenter
when :module
sorted_by_modules(assignments)
when :assignment_group
assignments.sort_by { |a| [a.assignment_group.position, a.position] }
assignments.sort_by { |a| [a.assignment_group.position, a.position].map{|p| p || CanvasSort::Last} }
end
end

View File

@ -3191,6 +3191,14 @@ describe AssignmentsApiController, type: :request do
end
end
it "should not be able to update position to nil" do
@assignment = @course.assignments.create!
json = api_update_assignment_call(@course, @assignment, {'position' => ''})
@assignment.reload
expect(json['position']).to eq 1
expect(@assignment.position).to eq 1
end
it "should process html content in description on update" do
@assignment = @course.assignments.create!