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>
This commit is contained in:
Cameron Matheson 2013-08-22 18:02:34 -06:00
parent 91804c6cc7
commit 8dcc790c69
5 changed files with 36 additions and 7 deletions

View File

@ -333,8 +333,8 @@ class GradebooksController < ApplicationController
end end
@comments, @failures = @assignment.generate_comments_from_files(params[:submissions_zip].path, @current_user) @comments, @failures = @assignment.generate_comments_from_files(params[:submissions_zip].path, @current_user)
flash[:notice] = t('notices.uploaded', flash[:notice] = t('notices.uploaded',
{ :one => "Files and comments created for 1 user submission", { :one => "Files and comments created for 1 submission",
:other => "Files and comments created for %{count} user submissions" }, :other => "Files and comments created for %{count} submissions" },
:count => @comments.length) :count => @comments.length)
end end

View File

@ -1216,12 +1216,20 @@ class Assignment < ActiveRecord::Base
file_map = zip_extractor.unzip_files.map { |f| infer_comment_context_from_filename(f) }.compact file_map = zip_extractor.unzip_files.map { |f| infer_comment_context_from_filename(f) }.compact
files_for_user = file_map.group_by { |f| f[:user] } files_for_user = file_map.group_by { |f| f[:user] }
comments = files_for_user.map do |user, files| comments = files_for_user.map do |user, files|
comment = t :comment_from_files, { :one => "See attached file", :other => "See attached files" }, :count => files.size
submission = files.first[:submission]
attachments = files.map { |g| attachments = files.map { |g|
FileInContext.attach(self, g[:filename], g[:display_name]) FileInContext.attach(self, g[:filename], g[:display_name])
} }
submission.add_comment(:comment => comment, :author => commenter, :attachments => attachments, :hidden => muted?) comment = {
comment: t(:comment_from_files, {one: "See attached file", other: "See attached files"}, count: files.size),
author: commenter,
hidden: muted?,
attachments: attachments,
}
group, students = group_students(user)
students.map { |student|
submission = find_or_create_submission(student)
submission.add_comment(comment)
}
end end
[comments.compact, @ignored_files] [comments.compact, @ignored_files]
end end

View File

@ -808,6 +808,7 @@ class Submission < ActiveRecord::Base
end end
if self.group if self.group
# this is a bit icky, as it assumes the same opts hash will be passed in to each add_comment call for the group # this is a bit icky, as it assumes the same opts hash will be passed in to each add_comment call for the group
# s|a bit icky|milk-curdling/vomit-inducing/baby-punching|
opts[:group_comment_id] ||= AutoHandle.generate_securish_uuid opts[:group_comment_id] ||= AutoHandle.generate_securish_uuid
end end
self.save! if self.new_record? self.save! if self.new_record?

View File

@ -64,7 +64,7 @@
<% if @comments.empty? %> <% if @comments.empty? %>
<li><%= t(:no_comments_added, "No Comments Added") %></li> <li><%= t(:no_comments_added, "No Comments Added") %></li>
<% end %> <% end %>
<% @comments.each do |comment| %> <% @comments.flatten.each do |comment| %>
<li> <li>
<a href="<%= context_url(@context, :context_assignment_submission_url, @assignment.id, comment.submission.user_id) %>"><%= comment.submission.user.name %></a> <a href="<%= context_url(@context, :context_assignment_submission_url, @assignment.id, comment.submission.user_id) %>"><%= comment.submission.user.name %></a>
<ul class="file_list"> <ul class="file_list">

View File

@ -2370,9 +2370,29 @@ describe Assignment do
zip.open.path, zip.open.path,
@teacher) @teacher)
comments.map { |c| c.submission.user }.should == [s1] comments.map { |g| g.map { |c| c.submission.user } }.should == [[s1]]
ignored.should be_empty ignored.should be_empty
end end
it "should work for groups" do
s1, s2 = @students
gc = @course.group_categories.create! name: "Homework Groups"
@assignment.update_attributes group_category_id: gc.id,
grade_group_students_individually: false
g1, g2 = 2.times.map { |i| gc.groups.create! name: "Group #{i}" }
g1.add_user(s1)
g1.add_user(s2)
submit_homework(s1)
zip = zip_submissions
comments, _ = @assignment.generate_comments_from_files(
zip.open.path,
@teacher)
comments.map { |g| g.map { |c| c.submission.user } }.should == [[s1, s2]]
end
end end
end end