Skip to content

Commit 267cad5

Browse files
Michael NomitchMarc Alan Phillips
authored andcommitted
add scoping overrides by active enrollment
Add scoping overrides by active enrollment to prevent unenrolled students with overrides from preventing assignments from saving. fixes CNVS-21655 test plan: - Create an assignment - Assign a due date to a particular student - Remove that user from the course - Edit that assignment. - Assignments override should no longer show. - Save the assignment should now work. Change-Id: If08da7119172c7918b15238195e39e07ae75ea16 Reviewed-on: https://gerrit.instructure.com/71305 Tested-by: Jenkins Reviewed-by: Davis McClellan <dmcclellan@instructure.com> QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Jason Sparks <jsparks@instructure.com>
1 parent 6274d43 commit 267cad5

7 files changed

Lines changed: 89 additions & 5 deletions

File tree

app/controllers/assignments_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def edit
422422
}),
423423
:ASSIGNMENT_OVERRIDES =>
424424
(assignment_overrides_json(
425-
@assignment.overrides_for(@current_user)
425+
@assignment.overrides_for(@current_user, ensure_set_not_empty: true)
426426
)),
427427
:ASSIGNMENT_INDEX_URL => polymorphic_url([@context, :assignments]),
428428
:DIFFERENTIATED_ASSIGNMENTS_ENABLED => @context.feature_enabled?(:differentiated_assignments),

app/controllers/discussion_topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def edit
402402
if @topic.assignment.present?
403403
hash[:ATTRIBUTES][:assignment][:assignment_overrides] =
404404
(assignment_overrides_json(
405-
@topic.assignment.overrides_for(@current_user)
405+
@topic.assignment.overrides_for(@current_user, ensure_set_not_empty: true)
406406
))
407407
hash[:ATTRIBUTES][:assignment][:has_student_submissions] = @topic.assignment.has_student_submissions?
408408
end

app/controllers/quizzes/quizzes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def edit
279279

280280
hash = {
281281
:ASSIGNMENT_ID => @assignment.present? ? @assignment.id : nil,
282-
:ASSIGNMENT_OVERRIDES => assignment_overrides_json(@quiz.overrides_for(@current_user)),
282+
:ASSIGNMENT_OVERRIDES => assignment_overrides_json(@quiz.overrides_for(@current_user, ensure_set_not_empty: true)),
283283
:DIFFERENTIATED_ASSIGNMENTS_ENABLED => @context.feature_enabled?(:differentiated_assignments),
284284
:QUIZ => quiz_json(@quiz, @context, @current_user, session),
285285
:SECTION_LIST => sections.map { |section|

app/models/assignment_override.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ class AssignmentOverride < ActiveRecord::Base
6969
after_save :update_cached_due_dates
7070
after_save :touch_assignment, :if => :assignment
7171

72+
def set_not_empty?
73+
overridable = assignment? ? assignment : quiz
74+
['CourseSection', 'Group'].include?(self.set_type) ||
75+
set.any? && overridable.context.current_enrollments.where(user_id: set).exists?
76+
end
77+
7278
def update_cached_due_dates
7379
return unless assignment?
7480
if due_at_overridden_changed? ||

lib/dates_overridable.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ def overridden_for(user)
2727
end
2828

2929
# All overrides, not just dates
30-
def overrides_for(user)
31-
AssignmentOverrideApplicator.overrides_for_assignment_and_user(self, user)
30+
def overrides_for(user, opts={})
31+
overrides = AssignmentOverrideApplicator.overrides_for_assignment_and_user(self, user)
32+
if opts[:ensure_set_not_empty]
33+
overrides.select(&:set_not_empty?)
34+
else
35+
overrides
36+
end
3237
end
3338

3439
def overridden_for?(user)

spec/lib/dates_overridable_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,45 @@
5959
end
6060
end
6161

62+
describe "assignment overrides_for" do
63+
before do
64+
student_in_course(:course => course)
65+
end
66+
67+
context "with adhoc" do
68+
before do
69+
override.override_due_at(7.days.from_now)
70+
override.set_type = "ADHOC"
71+
override.save!
72+
73+
end
74+
75+
it "returns adhoc overrides when active students enrolled in adhoc set" do
76+
override_student = override.assignment_override_students.build
77+
override_student.user = @student
78+
override_student.save!
79+
80+
expect(overridable.overrides_for(@student, ensure_set_not_empty: true).size).to eq 1
81+
end
82+
83+
it "returns nothing when no active students enrolled in adhoc set" do
84+
expect(overridable.overrides_for(@student, ensure_set_not_empty: true)).to be_empty
85+
end
86+
87+
it "returns nothing when active students enrolled in adhoc set removed" do
88+
override_student = override.assignment_override_students.build
89+
override_student.user = @student
90+
override_student.save!
91+
92+
expect(overridable.overrides_for(@student, ensure_set_not_empty: true).size).to eq 1
93+
94+
override_student.user.enrollments.delete_all
95+
96+
expect(overridable.overrides_for(@student, ensure_set_not_empty: true)).to be_empty
97+
end
98+
end
99+
end
100+
62101
describe "has_overrides?" do
63102
subject { overridable.has_overrides? }
64103

spec/models/assignment_override_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,4 +662,38 @@ def fancy_midnight(opts={})
662662
expect(@override.applies_to_students).to eq [@student]
663663
end
664664
end
665+
666+
describe "assignment_edits" do
667+
before do
668+
@override = assignment_override_model
669+
end
670+
671+
it "returns false if no students who are active in course for ADHOC" do
672+
@override.stubs(:set_type).returns "ADHOC"
673+
@override.stubs(:set).returns []
674+
675+
expect(@override.set_not_empty?).to eq false
676+
end
677+
678+
it "returns true if no students who are active in course and CourseSection or Group" do
679+
@override.stubs(:set_type).returns "CourseSection"
680+
@override.stubs(:set).returns []
681+
682+
expect(@override.set_not_empty?).to eq true
683+
684+
@override.stubs(:set_type).returns "Group"
685+
686+
expect(@override.set_not_empty?).to eq true
687+
end
688+
689+
it "returns true if has students who are active in course for ADHOC" do
690+
student = student_in_course(course: @override.assignment.context)
691+
@override.set_type = "ADHOC"
692+
@override_student = @override.assignment_override_students.build
693+
@override_student.user = student.user
694+
@override_student.save!
695+
696+
expect(@override.set_not_empty?).to eq true
697+
end
698+
end
665699
end

0 commit comments

Comments
 (0)