Skip to content

Commit 8dcc790

Browse files
committed
make submission uploads support group commenting
closes CNVS-6879 Test plan: * make a group assignment * submit homework for some groups * download the submissions * upload the submissions * the uploaded attachments should have gone to each student in the group Change-Id: Ia2d95eb13b75803c184441bb07ec853bf75e4938 Reviewed-on: https://gerrit.instructure.com/23661 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Product-Review: Cameron Matheson <cameron@instructure.com>
1 parent 91804c6 commit 8dcc790

5 files changed

Lines changed: 36 additions & 7 deletions

File tree

app/controllers/gradebooks_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ def submissions_zip_upload
333333
end
334334
@comments, @failures = @assignment.generate_comments_from_files(params[:submissions_zip].path, @current_user)
335335
flash[:notice] = t('notices.uploaded',
336-
{ :one => "Files and comments created for 1 user submission",
337-
:other => "Files and comments created for %{count} user submissions" },
336+
{ :one => "Files and comments created for 1 submission",
337+
:other => "Files and comments created for %{count} submissions" },
338338
:count => @comments.length)
339339
end
340340

app/models/assignment.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,20 @@ def generate_comments_from_files(filename, commenter)
12161216
file_map = zip_extractor.unzip_files.map { |f| infer_comment_context_from_filename(f) }.compact
12171217
files_for_user = file_map.group_by { |f| f[:user] }
12181218
comments = files_for_user.map do |user, files|
1219-
comment = t :comment_from_files, { :one => "See attached file", :other => "See attached files" }, :count => files.size
1220-
submission = files.first[:submission]
12211219
attachments = files.map { |g|
12221220
FileInContext.attach(self, g[:filename], g[:display_name])
12231221
}
1224-
submission.add_comment(:comment => comment, :author => commenter, :attachments => attachments, :hidden => muted?)
1222+
comment = {
1223+
comment: t(:comment_from_files, {one: "See attached file", other: "See attached files"}, count: files.size),
1224+
author: commenter,
1225+
hidden: muted?,
1226+
attachments: attachments,
1227+
}
1228+
group, students = group_students(user)
1229+
students.map { |student|
1230+
submission = find_or_create_submission(student)
1231+
submission.add_comment(comment)
1232+
}
12251233
end
12261234
[comments.compact, @ignored_files]
12271235
end

app/models/submission.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ def add_comment(opts={})
808808
end
809809
if self.group
810810
# this is a bit icky, as it assumes the same opts hash will be passed in to each add_comment call for the group
811+
# s|a bit icky|milk-curdling/vomit-inducing/baby-punching|
811812
opts[:group_comment_id] ||= AutoHandle.generate_securish_uuid
812813
end
813814
self.save! if self.new_record?

app/views/gradebooks/submissions_zip_upload.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<% if @comments.empty? %>
6565
<li><%= t(:no_comments_added, "No Comments Added") %></li>
6666
<% end %>
67-
<% @comments.each do |comment| %>
67+
<% @comments.flatten.each do |comment| %>
6868
<li>
6969
<a href="<%= context_url(@context, :context_assignment_submission_url, @assignment.id, comment.submission.user_id) %>"><%= comment.submission.user.name %></a>
7070
<ul class="file_list">

spec/models/assignment_spec.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,9 +2370,29 @@ def stub_plugin
23702370
zip.open.path,
23712371
@teacher)
23722372

2373-
comments.map { |c| c.submission.user }.should == [s1]
2373+
comments.map { |g| g.map { |c| c.submission.user } }.should == [[s1]]
23742374
ignored.should be_empty
23752375
end
2376+
2377+
it "should work for groups" do
2378+
s1, s2 = @students
2379+
2380+
gc = @course.group_categories.create! name: "Homework Groups"
2381+
@assignment.update_attributes group_category_id: gc.id,
2382+
grade_group_students_individually: false
2383+
g1, g2 = 2.times.map { |i| gc.groups.create! name: "Group #{i}" }
2384+
g1.add_user(s1)
2385+
g1.add_user(s2)
2386+
2387+
submit_homework(s1)
2388+
zip = zip_submissions
2389+
2390+
comments, _ = @assignment.generate_comments_from_files(
2391+
zip.open.path,
2392+
@teacher)
2393+
2394+
comments.map { |g| g.map { |c| c.submission.user } }.should == [[s1, s2]]
2395+
end
23762396
end
23772397
end
23782398

0 commit comments

Comments
 (0)