enforce no changing group_category on assignments after submissions
refs CNVS-11813 Test plan: * create an assignment * assign a group category to it (this should work) * remove the group category (this should work) * submit some homework * use the API to try and change the group category. it won't let you Change-Id: I09a56e281956d30e9213d6105bd9c75ede97da1c Reviewed-on: https://gerrit.instructure.com/32719 QA-Review: Caleb Guanzon <cguanzon@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> Product-Review: Cameron Matheson <cameron@instructure.com>
This commit is contained in:
parent
c0bde16e77
commit
3e3d484b79
|
@ -61,6 +61,7 @@ class Assignment < ActiveRecord::Base
|
|||
has_one :external_tool_tag, :class_name => 'ContentTag', :as => :context, :dependent => :destroy
|
||||
validates_associated :external_tool_tag, :if => :external_tool?
|
||||
validate :validate_draft_state_change, :if => :workflow_state_changed?
|
||||
validate :group_category_changes_ok?
|
||||
|
||||
accepts_nested_attributes_for :external_tool_tag, :update_only => true, :reject_if => proc { |attrs|
|
||||
# only accept the url and new_tab params, the other accessible
|
||||
|
@ -82,6 +83,15 @@ class Assignment < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
def group_category_changes_ok?
|
||||
return if new_record?
|
||||
return unless has_submitted_submissions?
|
||||
if group_category_id_changed?
|
||||
errors.add :group_category_id, I18n.t("group_category_locked",
|
||||
"The group category can't be changed because students have already submitted on this assignment")
|
||||
end
|
||||
end
|
||||
|
||||
API_NEEDED_FIELDS = %w(
|
||||
id
|
||||
title
|
||||
|
|
|
@ -2638,6 +2638,44 @@ describe Assignment do
|
|||
@assignment.save!
|
||||
end
|
||||
end
|
||||
|
||||
describe "group category validation" do
|
||||
before do
|
||||
student_in_course active_all: true
|
||||
@group_category = @course.group_categories.create! name: "groups"
|
||||
@groups = 2.times.map { |i|
|
||||
@group_category.groups.create! name: "group #{i}", context: @course
|
||||
}
|
||||
end
|
||||
|
||||
def assignment(group_category = nil)
|
||||
a = @course.assignments.build name: "test"
|
||||
a.group_category = group_category
|
||||
a.tap &:save!
|
||||
end
|
||||
|
||||
it "lets you change group category attributes before homework is submitted" do
|
||||
a1 = assignment
|
||||
a1.group_category = @group_category
|
||||
a1.should be_valid
|
||||
|
||||
a2 = assignment(@group_category)
|
||||
a2.group_category = nil
|
||||
a2.should be_valid
|
||||
end
|
||||
|
||||
it "doesn't let you change group category attributes after homework is submitted" do
|
||||
a1 = assignment
|
||||
a1.submit_homework @student, body: "hello, world"
|
||||
a1.group_category = @group_category
|
||||
a1.should_not be_valid
|
||||
|
||||
a2 = assignment(@group_category)
|
||||
a2.submit_homework @student, body: "hello, world"
|
||||
a2.group_category = nil
|
||||
a2.should_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup_assignment_with_group
|
||||
|
|
Loading…
Reference in New Issue