From df6d8b969ba2bfb520a0b7f69f0092f7ed1a76f6 Mon Sep 17 00:00:00 2001 From: Cameron Matheson Date: Mon, 22 Sep 2014 16:28:29 -0600 Subject: [PATCH] show groupless submissions in speedgrader fixes CNVS-15753 Test plan: * make a group assignment with a group category that has no groups * submit some homework * the submissions should display (and be gradeable) in speedgrader * add some groups (with people in them) * submit more homework for the people with groups * the submissions for people in groups and people not in groups should all display * downloading submissions should work as well Change-Id: I7e6081cec61936c4f833394e995963698f4b57b7 Reviewed-on: https://gerrit.instructure.com/41596 Tested-by: Jenkins Reviewed-by: Matt Berns Reviewed-by: Mike Nomitch QA-Review: Sean Lewis Product-Review: Simon Williams --- app/models/assignment.rb | 15 ++++++++++++--- spec/models/assignment_spec.rb | 6 ++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/models/assignment.rb b/app/models/assignment.rb index d47832ff445..b03087a348e 100644 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -1395,9 +1395,7 @@ class Assignment < ActiveRecord::Base else [] end - group_category.groups.includes(:group_memberships => :user).map { |g| - [g.name, g.users] - }.map { |group_name, group_students| + groups_and_ungrouped(user).map { |group_name, group_students| visible_group_students = group_students & visible_students_for_speed_grader(user) representative = (visible_group_students & users_with_turnitin_data).first representative ||= (visible_group_students & users_with_submissions).first @@ -1419,6 +1417,17 @@ class Assignment < ActiveRecord::Base end end + def groups_and_ungrouped(user) + groups_and_users = group_category. + groups.includes(:group_memberships => :user). + map { |g| [g.name, g.users] } + users_in_group = groups_and_users.flat_map { |_,users| users } + groupless_users = visible_students_for_speed_grader(user) - users_in_group + phony_groups = groupless_users.map { |u| [u.name, [u]] } + groups_and_users + phony_groups + end + private :groups_and_ungrouped + # using this method instead of students_with_visibility so we # can add the includes and students_visible_to/participating_students scopes def visible_students_for_speed_grader(user) diff --git a/spec/models/assignment_spec.rb b/spec/models/assignment_spec.rb index 9dfb89afedd..58b9b7f376f 100644 --- a/spec/models/assignment_spec.rb +++ b/spec/models/assignment_spec.rb @@ -2501,6 +2501,7 @@ describe Assignment do context "group assignments" do before :once do + course_with_teacher(active_all: true) gc = @course.group_categories.create! name: "Assignment Groups" @groups = 2.times.map { |i| gc.groups.create! name: "Group #{i}", context: @course } students = create_users_in_course(@course, 4, return_type: :record) @@ -2551,6 +2552,11 @@ describe Assignment do s.update_attribute :submission_type, 'online_upload' @assignment.representatives(@teacher).should include g1rep end + + it "includes users who aren't in a group" do + student_in_course active_all: true + @assignment.representatives(@teacher).last.should == @student + end end context "quizzes" do