generate UUID before adding group comments to submission

when adding group comments, we had been using a kludge
which attempted to add comments to a submission on
behalf of each student in a group, expecting the
exact same options hash every time. This fixes that
by moving generation of the group comment's unique ID
to the caller

Change-Id: I1920efffa2f5fc0150a4173abc1b8fa5490f2bd5
Reviewed-on: https://gerrit.instructure.com/29304
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Anthus Williams <awilliams@instructure.com>
Product-Review: Anthus Williams <awilliams@instructure.com>
QA-Review: Anthus Williams <awilliams@instructure.com>
This commit is contained in:
Anthus Williams 2014-01-14 13:57:50 -07:00
parent 831aa742fa
commit d67913fde9
2 changed files with 11 additions and 9 deletions

View File

@ -871,7 +871,7 @@ class Assignment < ActiveRecord::Base
raise "Student must be enrolled in the course as a student to be graded" unless context.includes_student?(original_student)
raise "Grader must be enrolled as a course admin" if opts[:grader] && !self.context.grants_right?(opts[:grader], nil, :manage_grades)
opts.delete(:id)
group_comment = opts.delete :group_comment
group_comment = Canvas::Plugin.value_to_boolean(opts.delete(:group_comment))
group, students = group_students(original_student)
grader = opts.delete :grader
comment = {
@ -881,6 +881,7 @@ class Assignment < ActiveRecord::Base
:media_comment_id => (opts.delete :media_comment_id),
:media_comment_type => (opts.delete :media_comment_type),
}
comment[:group_comment_id] = AutoHandle.generate_securish_uuid if group_comment && group
submissions = []
find_or_create_submissions(students) do |submission|
submission_updated = false
@ -911,8 +912,8 @@ class Assignment < ActiveRecord::Base
submission.graded_at = Time.zone.now if did_grade
previously_graded ? submission.with_versioning(:explicit => true) { submission.save! } : submission.save!
end
submission.add_comment(comment) if comment && (group_comment == "1" || student == original_student)
submissions << submission if group_comment == "1" || student == original_student || submission_updated
submission.add_comment(comment) if comment && (group_comment || student == original_student)
submissions << submission if group_comment || student == original_student || submission_updated
end
submissions
@ -988,6 +989,7 @@ class Assignment < ActiveRecord::Base
res = find_or_create_submissions(students) do |s|
s.group = group
s.save! if s.changed?
opts[:group_comment_id] = AutoHandle.generate_securish_uuid if group
s.add_comment(opts)
# this is lame, SubmissionComment updates the submission directly in the db
# in an after_save, and of course Rails doesn't preload the reverse association
@ -1058,7 +1060,11 @@ class Assignment < ActiveRecord::Base
end
homeworks.each do |homework|
context_module_action(homework.student, :submitted)
homework.add_comment({:comment => comment, :author => original_student}) if comment && (group_comment || homework == primary_homework)
if comment && (group_comment || homework == primary_homework)
hash = {:comment => comment, :author => original_student}
hash[:group_comment_id] = AutoHandle.generate_securish_uuid if group_comment && group
homework.add_comment(hash)
end
end
touch_context
return primary_homework
@ -1279,6 +1285,7 @@ class Assignment < ActiveRecord::Base
attachments: attachments,
}
group, students = group_students(user)
comment[:group_comment_id] = AutoHandle.generate_securish_uuid if group
find_or_create_submissions(students).map do |submission|
submission.add_comment(comment)
end

View File

@ -829,11 +829,6 @@ class Submission < ActiveRecord::Base
opts[:comment] = t('attached_files_comment', "See attached files.")
end
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?
valid_keys = [:comment, :author, :media_comment_id, :media_comment_type,
:group_comment_id, :assessment_request, :attachments,