Skip to content

Commit f7cf266

Browse files
committed
DA - needs grading
fixes CNVS-15482 test plan: * with DA on - create an assignment and submit it as several students in different sections - as a teacher again, change the assignment to only be visible to one section (one that has student submissions) > on your dashboard, only the students' submissions from that section should show in your 'needs grading' right-side bar > on the course dashboard the same should be true - as a section limited teacher who is limited to the section with visibility, your dashboard and course dashboard should only show submissions from your section as needing grading * with DA off - repeat the steps above and all submissions should be in the needs grading count in all places Change-Id: I6c2fad7d7dea42c2e7edc968e8db113bdcab3a3c Reviewed-on: https://gerrit.instructure.com/41604 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Mike Nomitch <mnomitch@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Product-Review: Hilary Scharton <hilary@instructure.com>
1 parent 87beaac commit f7cf266

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

app/models/assignments/needs_grading_count_query.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def count
1313
Rails.cache.fetch(['assignment_user_grading_count', assignment, user].cache_key) do
1414
case visibility_level
1515
when :full, :limited
16-
assignment.needs_grading_count
16+
da_enabled? ? manual_count : assignment.needs_grading_count
1717
when :sections
1818
section_filtered_submissions.count(:id, distinct: true)
1919
else
@@ -40,13 +40,21 @@ def count_by_section
4040
end
4141
end
4242

43+
def manual_count
44+
assignment.shard.activate do
45+
Rails.cache.fetch(['assignment_user_grading_manual_count', assignment, user].cache_key) do
46+
all_submissions.count
47+
end
48+
end
49+
end
50+
4351
private
4452
def section_filtered_submissions
4553
all_submissions.where('e.course_section_id in (?)', visible_section_ids)
4654
end
4755

4856
def all_submissions
49-
joined_submissions.where(<<-SQL, assignment, course)
57+
string = <<-SQL
5058
submissions.assignment_id = ?
5159
AND e.course_id = ?
5260
AND e.type IN ('StudentEnrollment', 'StudentViewEnrollment')
@@ -56,6 +64,13 @@ def all_submissions
5664
OR (submissions.workflow_state = 'submitted'
5765
AND (submissions.score IS NULL OR NOT submissions.grade_matches_current_submission)))
5866
SQL
67+
68+
if da_enabled?
69+
string += <<-SQL
70+
AND EXISTS (SELECT * FROM assignment_student_visibilities asv WHERE asv.user_id = submissions.user_id AND asv.assignment_id = submissions.assignment_id)
71+
SQL
72+
end
73+
joined_submissions.where(string, assignment, course)
5974
end
6075

6176
def joined_submissions
@@ -77,5 +92,9 @@ def section_visibilities
7792
def course
7893
assignment.context
7994
end
95+
96+
def da_enabled?
97+
course.feature_enabled?(:differentiated_assignments)
98+
end
8099
end
81100
end

app/models/submission.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ def self.needs_grading_trigger_sql
144144
AND #{Enrollment.active_student_subselect("user_id = NEW.user_id AND course_id = assignments.context_id")};
145145
SQL
146146

147+
# TODO: add this to the SQL above when DA is on for everybody
148+
# and don't forget to run `rake db:generate_trigger_migration`
149+
# and remove NeedsGradingCountQuery#manual_count
150+
# AND EXISTS(SELECT assignment_student_visibilities.* WHERE assignment_student_visibilities.user_id = NEW.user_id AND assignment_student_visibilities.assignment_id = NEW.assignment_id);
151+
147152
{ :default => default_sql.gsub("{{now}}", "now()"),
148153
:postgresql => default_sql.gsub("{{now}}", "now() AT TIME ZONE 'UTC'"),
149154
:sqlite => default_sql.gsub("{{now}}", "datetime('now')"),

spec/models/assignments/needs_grading_count_query_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,5 @@ module Assignments
9090
end
9191
end
9292
end
93-
9493
end
9594
end

spec/models/user_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,31 @@ def create_course_with_assignment_needing_submitting(opts={})
23502350
@teacher.assignments_needing_grading(:limit => 1).length.should == 1
23512351
end
23522352
end
2353+
2354+
context "differentiated assignments" do
2355+
before :once do
2356+
@a2 = @course1.assignments.create!(:title => "some assignment 2", :submission_types => ['online_text_entry'])
2357+
[@studentA, @studentB].each do |student|
2358+
@a2.submit_homework student, body: "submission for #{student.name}"
2359+
end
2360+
2361+
@section1a = @course1.course_sections.create!(name: 'Section One')
2362+
student_in_section(@section1a, user: @studentB)
2363+
2364+
assignments = @course1.assignments
2365+
differentiated_assignment(assignment: assignments[0], course_section: @section1b)
2366+
differentiated_assignment(assignment: assignments[1], course_section: @section1a)
2367+
end
2368+
2369+
it "should not include submissions from students without visibility" do
2370+
@course1.enable_feature!(:differentiated_assignments)
2371+
@teacher.assignments_needing_grading.length.should == 2
2372+
end
2373+
2374+
it "should show all submissions with the feature flag off" do
2375+
@teacher.assignments_needing_grading.length.should == 3
2376+
end
2377+
end
23532378
end
23542379

23552380
describe ".initial_enrollment_type_from_type" do

0 commit comments

Comments
 (0)