Skip to content

Commit

Permalink
fix checks for muted/unposted submissions in submission comments
Browse files Browse the repository at this point in the history
With the change to post policies, we need to check if the submission
is posted and not check against the assignment muted attribute.

fixes GRADE-2369

test plan:
 - Create a course with new gradebook and post policies enabled, a
   teacher, and a student
 - In the course, create an assignment and set the assignment to
   manual posting
 - As a teacher, leave a submission comment
 - Confirm no notifications went out
 - In the rails console, confirm that no ContentParticipation object
   was created

Change-Id: Ib5ac4d010acf1462ac56f55546e7dbf17292c56d
Reviewed-on: https://gerrit.instructure.com/205616
Reviewed-by: Adrian Packel <[email protected]>
Reviewed-by: Gary Mei <[email protected]>
Tested-by: Jenkins
QA-Review: Derek Bender <[email protected]>
Product-Review: Keith Garner <[email protected]>
  • Loading branch information
ktgeek committed Aug 21, 2019
1 parent cb8225d commit 68ddb0f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/submission_comment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#
# Copyright (C) 2011 - present Instructure, Inc.
#
Expand Down Expand Up @@ -183,7 +184,7 @@ def check_for_media_object
record.provisional_grade_id.nil? &&
record.submission.assignment &&
record.submission.assignment.context.available? &&
!record.submission.assignment.muted? &&
record.submission.posted? &&
record.submission.assignment.context.grants_right?(record.submission.user, :read) &&
(!record.submission.assignment.context.instructors.include?(author) || record.submission.assignment.published?)
}
Expand Down Expand Up @@ -367,7 +368,7 @@ def update_participation
# id_changed? because new_record? is false in after_save callbacks
if saved_change_to_id? || (saved_change_to_hidden? && !hidden?)
return if submission.user_id == author_id
return if submission.assignment.deleted? || submission.assignment.muted?
return if submission.assignment.deleted? || !submission.posted?
return if provisional_grade_id.present?

self.class.connection.after_transaction_commit do
Expand Down
62 changes: 62 additions & 0 deletions spec/models/submission_comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@
expect(@comment.messages_sent).to be_include('Submission Comment For Teacher')
end

context "muted assignments" do
it "doesn't dispatch notification on create" do
@assignment.mute!

@comment = @submission.add_comment(author: @teacher, comment: "some comment")
expect(@comment.messages_sent.keys).not_to include('Submission Comment')
end
end

context "post policies" do
before(:once) do
@course.enable_feature!(:new_gradebook)
PostPolicy.enable_feature!
end

it "doesn't dispatch notifications on create for manually posted assignments" do
@assignment.post_policy.update_attribute(:post_manually, true)
@assignment.hide_submissions(submission_ids: [@submission.id])

@comment = @submission.add_comment(author: @teacher, comment: "some comment")
expect(@comment.messages_sent.keys).not_to include('Submission Comment')
end
end

context 'draft comment' do
before(:each) do
@comment = @submission.add_comment(author: @teacher, comment: '42', draft_comment: true)
Expand Down Expand Up @@ -714,4 +738,42 @@ def prepare_test_submission
expect(@comment1).not_to be_valid
end
end

describe "after_save#update_participation" do
context "muted/unmuted assignments" do
it "doesn't update participation for a muted assignment" do
@assignment.mute!

expect(ContentParticipation).to_not receive(:create_or_update)
@comment = @submission.add_comment(author: @teacher, comment: "some comment")
end

it "updates particiapation for an unmuted assignment" do
expect(ContentParticipation).to receive(:create_or_update).
with({content: @submission, user: @submission.user, workflow_state: "unread"})
@comment = @submission.add_comment(author: @teacher, comment: "some comment")
end
end

context "post policies" do
before(:once) do
@course.enable_feature!(:new_gradebook)
PostPolicy.enable_feature!
end

it "doesn't update participation for a manually posted assignment" do
@assignment.post_policy.update_attribute(:post_manually, true)
@assignment.hide_submissions(submission_ids: [@submission.id])

expect(ContentParticipation).to_not receive(:create_or_update)
@comment = @submission.add_comment(author: @teacher, comment: "some comment")
end

it "updates participation for an automatically posted assignment" do
expect(ContentParticipation).to receive(:create_or_update).
with({content: @submission, user: @submission.user, workflow_state: "unread"})
@comment = @submission.add_comment(author: @teacher, comment: "some comment")
end
end
end
end

0 comments on commit 68ddb0f

Please sign in to comment.