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
@comments, @failures = @assignment.generate_comments_from_files(params[:submissions_zip].path, @current_user)
flash[:notice] = t('notices.uploaded',
{ :one => "Files and comments created for 1 user submission",
:other => "Files and comments created for %{count} user submissions" },
{ :one => "Files and comments created for 1 submission",
:other => "Files and comments created for %{count} submissions" },
:count => @comments.length)
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
files_for_user = file_map.group_by { |f| f[:user] }
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|
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
[comments.compact, @ignored_files]
end

View File

@ -808,6 +808,7 @@ class Submission < ActiveRecord::Base
end
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
# s|a bit icky|milk-curdling/vomit-inducing/baby-punching|
opts[:group_comment_id] ||= AutoHandle.generate_securish_uuid
end
self.save! if self.new_record?

View File

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

View File

@ -2370,9 +2370,29 @@ describe Assignment do
zip.open.path,
@teacher)
comments.map { |c| c.submission.user }.should == [s1]
comments.map { |g| g.map { |c| c.submission.user } }.should == [[s1]]
ignored.should be_empty
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