2017-04-28 04:05:04 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 - present Instructure, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2011-09-15 06:41:56 +08:00
|
|
|
module Mutable
|
|
|
|
|
|
|
|
attr_accessor :recently_unmuted
|
|
|
|
|
|
|
|
def self.included(base)
|
|
|
|
base.extend(ClassMethods)
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
def declare_mutable_broadcast_policy(options)
|
|
|
|
policy = options[:policy]
|
|
|
|
participants = options[:participants]
|
|
|
|
|
|
|
|
policy.dispatch :assignment_unmuted
|
|
|
|
policy.to { participants }
|
|
|
|
policy.whenever do |record|
|
|
|
|
@recently_unmuted
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def mute!
|
2015-07-19 09:21:38 +08:00
|
|
|
return if muted?
|
2011-09-15 06:41:56 +08:00
|
|
|
self.update_attribute(:muted, true)
|
|
|
|
clear_sent_messages
|
Make muting compatible w/ post policies
Allow an assignment to post/unpost an arbitrary set of submissions, and
use this workflow for muting/unmuting. When post policies are enabled,
determine an assignment's muted? status based on whether it has any
unposted submissions (and update it as submissions are posted/unposted).
When the user manually mutes/unmutes an assignment, adjust its post
policy accordingly.
closes GRADE-1875
Test plan:
- For a course with the the Post Policies feature flag enabled:
- Create some assignments to play around with
- Creating an anonymous or moderated assignment (or changing an
existing one) should automatically create an associated
PostPolicy object with post_manually set to true
- Otherwise, a PostPolicy should not automatically be created
- (To check this, you'll need to look at assignment.post_policy
in a console; it's not visible in the UI yet)
- Muting an assignment (from the UI or using mute!) should:
- Save a post_policy for the assignment with post_manually set to
true (if not already set)
- Set posted_at for all active submissions to nil
- Do the usual other stuff like hiding submission comments
- Have no effect if all submissions are already unposted
- Unmuting an assignment (from the UI or using unmute!) should:
- Save a post_policy for the assignment with post_manually set to
false (if not already set)
- Set posted_at for all active submissions to the current date
- Do the usual other stuff like showing submission comments
- Have no effect if all submissions are already posted
- In a Rails console, find an assignment/some submissions to test with
> assignment.post_submissions(submissions: submissions)
- This should post the given submissions (i.e., set posted_at,
show comments, etc.) but no others
> assignment.unpost_submissions(submissions: submissions)
- This should unpost only the given submissions
- Both methods should update the assignment's muted attribute
automatically:
- Muted should be set to true if any active submissions on the
assignment remain unposted, and false if all are posted
- Note: setting the posted_at time on an individual submission
will NOT auto-update the assignment's muted status (as of this
patchset)
- For a course with the the Post Policies feature flag *disabled*:
- Muting/unmuting an assignment should work as usual, and should
*not* attempt to create a post policy on the assignment
- It should, however, still set or unset the posted_at date on
all the assignment's submissions
- In a Rails console:
- The muted? attribute should behave like before (i.e., it should
not be dynamically updated if a subset of submissions is posted
or unposted)
Change-Id: I317dee609fe92cf2832d36bff54511abeb72137c
Reviewed-on: https://gerrit.instructure.com/179361
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Jenkins
QA-Review: Gary Mei <gmei@instructure.com>
Product-Review: Keith Garner <kgarner@instructure.com>
2019-01-26 00:40:32 +08:00
|
|
|
unpost_submissions if respond_to?(:unpost_submissions)
|
|
|
|
ensure_post_policy(post_manually: true) if respond_to?(:ensure_post_policy)
|
2017-04-11 21:37:10 +08:00
|
|
|
true
|
2011-09-15 06:41:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def unmute!
|
2015-07-19 09:21:38 +08:00
|
|
|
return unless muted?
|
2011-09-15 06:41:56 +08:00
|
|
|
self.update_attribute(:muted, false)
|
|
|
|
broadcast_unmute_event
|
Make muting compatible w/ post policies
Allow an assignment to post/unpost an arbitrary set of submissions, and
use this workflow for muting/unmuting. When post policies are enabled,
determine an assignment's muted? status based on whether it has any
unposted submissions (and update it as submissions are posted/unposted).
When the user manually mutes/unmutes an assignment, adjust its post
policy accordingly.
closes GRADE-1875
Test plan:
- For a course with the the Post Policies feature flag enabled:
- Create some assignments to play around with
- Creating an anonymous or moderated assignment (or changing an
existing one) should automatically create an associated
PostPolicy object with post_manually set to true
- Otherwise, a PostPolicy should not automatically be created
- (To check this, you'll need to look at assignment.post_policy
in a console; it's not visible in the UI yet)
- Muting an assignment (from the UI or using mute!) should:
- Save a post_policy for the assignment with post_manually set to
true (if not already set)
- Set posted_at for all active submissions to nil
- Do the usual other stuff like hiding submission comments
- Have no effect if all submissions are already unposted
- Unmuting an assignment (from the UI or using unmute!) should:
- Save a post_policy for the assignment with post_manually set to
false (if not already set)
- Set posted_at for all active submissions to the current date
- Do the usual other stuff like showing submission comments
- Have no effect if all submissions are already posted
- In a Rails console, find an assignment/some submissions to test with
> assignment.post_submissions(submissions: submissions)
- This should post the given submissions (i.e., set posted_at,
show comments, etc.) but no others
> assignment.unpost_submissions(submissions: submissions)
- This should unpost only the given submissions
- Both methods should update the assignment's muted attribute
automatically:
- Muted should be set to true if any active submissions on the
assignment remain unposted, and false if all are posted
- Note: setting the posted_at time on an individual submission
will NOT auto-update the assignment's muted status (as of this
patchset)
- For a course with the the Post Policies feature flag *disabled*:
- Muting/unmuting an assignment should work as usual, and should
*not* attempt to create a post policy on the assignment
- It should, however, still set or unset the posted_at date on
all the assignment's submissions
- In a Rails console:
- The muted? attribute should behave like before (i.e., it should
not be dynamically updated if a subset of submissions is posted
or unposted)
Change-Id: I317dee609fe92cf2832d36bff54511abeb72137c
Reviewed-on: https://gerrit.instructure.com/179361
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Jenkins
QA-Review: Gary Mei <gmei@instructure.com>
Product-Review: Keith Garner <kgarner@instructure.com>
2019-01-26 00:40:32 +08:00
|
|
|
post_submissions if respond_to?(:post_submissions)
|
|
|
|
ensure_post_policy(post_manually: false) if respond_to?(:ensure_post_policy)
|
2017-04-11 21:37:10 +08:00
|
|
|
true
|
2011-09-15 06:41:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def broadcast_unmute_event
|
|
|
|
@recently_unmuted = true
|
|
|
|
self.save!
|
|
|
|
@recently_unmuted = false
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
def clear_sent_messages
|
|
|
|
self.clear_broadcast_messages if self.respond_to? :clear_broadcast_messages
|
|
|
|
end
|
|
|
|
|
Make muting compatible w/ post policies
Allow an assignment to post/unpost an arbitrary set of submissions, and
use this workflow for muting/unmuting. When post policies are enabled,
determine an assignment's muted? status based on whether it has any
unposted submissions (and update it as submissions are posted/unposted).
When the user manually mutes/unmutes an assignment, adjust its post
policy accordingly.
closes GRADE-1875
Test plan:
- For a course with the the Post Policies feature flag enabled:
- Create some assignments to play around with
- Creating an anonymous or moderated assignment (or changing an
existing one) should automatically create an associated
PostPolicy object with post_manually set to true
- Otherwise, a PostPolicy should not automatically be created
- (To check this, you'll need to look at assignment.post_policy
in a console; it's not visible in the UI yet)
- Muting an assignment (from the UI or using mute!) should:
- Save a post_policy for the assignment with post_manually set to
true (if not already set)
- Set posted_at for all active submissions to nil
- Do the usual other stuff like hiding submission comments
- Have no effect if all submissions are already unposted
- Unmuting an assignment (from the UI or using unmute!) should:
- Save a post_policy for the assignment with post_manually set to
false (if not already set)
- Set posted_at for all active submissions to the current date
- Do the usual other stuff like showing submission comments
- Have no effect if all submissions are already posted
- In a Rails console, find an assignment/some submissions to test with
> assignment.post_submissions(submissions: submissions)
- This should post the given submissions (i.e., set posted_at,
show comments, etc.) but no others
> assignment.unpost_submissions(submissions: submissions)
- This should unpost only the given submissions
- Both methods should update the assignment's muted attribute
automatically:
- Muted should be set to true if any active submissions on the
assignment remain unposted, and false if all are posted
- Note: setting the posted_at time on an individual submission
will NOT auto-update the assignment's muted status (as of this
patchset)
- For a course with the the Post Policies feature flag *disabled*:
- Muting/unmuting an assignment should work as usual, and should
*not* attempt to create a post policy on the assignment
- It should, however, still set or unset the posted_at date on
all the assignment's submissions
- In a Rails console:
- The muted? attribute should behave like before (i.e., it should
not be dynamically updated if a subset of submissions is posted
or unposted)
Change-Id: I317dee609fe92cf2832d36bff54511abeb72137c
Reviewed-on: https://gerrit.instructure.com/179361
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Jenkins
QA-Review: Gary Mei <gmei@instructure.com>
Product-Review: Keith Garner <kgarner@instructure.com>
2019-01-26 00:40:32 +08:00
|
|
|
def hide_stream_items(submissions:)
|
|
|
|
if submissions.present?
|
|
|
|
submission_ids = submissions.pluck(:id)
|
2013-03-19 23:49:31 +08:00
|
|
|
stream_items = StreamItem.select([:id, :context_type, :context_id]).
|
Make muting compatible w/ post policies
Allow an assignment to post/unpost an arbitrary set of submissions, and
use this workflow for muting/unmuting. When post policies are enabled,
determine an assignment's muted? status based on whether it has any
unposted submissions (and update it as submissions are posted/unposted).
When the user manually mutes/unmutes an assignment, adjust its post
policy accordingly.
closes GRADE-1875
Test plan:
- For a course with the the Post Policies feature flag enabled:
- Create some assignments to play around with
- Creating an anonymous or moderated assignment (or changing an
existing one) should automatically create an associated
PostPolicy object with post_manually set to true
- Otherwise, a PostPolicy should not automatically be created
- (To check this, you'll need to look at assignment.post_policy
in a console; it's not visible in the UI yet)
- Muting an assignment (from the UI or using mute!) should:
- Save a post_policy for the assignment with post_manually set to
true (if not already set)
- Set posted_at for all active submissions to nil
- Do the usual other stuff like hiding submission comments
- Have no effect if all submissions are already unposted
- Unmuting an assignment (from the UI or using unmute!) should:
- Save a post_policy for the assignment with post_manually set to
false (if not already set)
- Set posted_at for all active submissions to the current date
- Do the usual other stuff like showing submission comments
- Have no effect if all submissions are already posted
- In a Rails console, find an assignment/some submissions to test with
> assignment.post_submissions(submissions: submissions)
- This should post the given submissions (i.e., set posted_at,
show comments, etc.) but no others
> assignment.unpost_submissions(submissions: submissions)
- This should unpost only the given submissions
- Both methods should update the assignment's muted attribute
automatically:
- Muted should be set to true if any active submissions on the
assignment remain unposted, and false if all are posted
- Note: setting the posted_at time on an individual submission
will NOT auto-update the assignment's muted status (as of this
patchset)
- For a course with the the Post Policies feature flag *disabled*:
- Muting/unmuting an assignment should work as usual, and should
*not* attempt to create a post policy on the assignment
- It should, however, still set or unset the posted_at date on
all the assignment's submissions
- In a Rails console:
- The muted? attribute should behave like before (i.e., it should
not be dynamically updated if a subset of submissions is posted
or unposted)
Change-Id: I317dee609fe92cf2832d36bff54511abeb72137c
Reviewed-on: https://gerrit.instructure.com/179361
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Jenkins
QA-Review: Gary Mei <gmei@instructure.com>
Product-Review: Keith Garner <kgarner@instructure.com>
2019-01-26 00:40:32 +08:00
|
|
|
where(asset_type: 'Submission', asset_id: submission_ids).
|
|
|
|
preload(:context).to_a
|
2012-11-17 06:00:05 +08:00
|
|
|
stream_item_contexts = stream_items.map { |si| [si.context_type, si.context_id] }
|
2016-08-03 03:51:43 +08:00
|
|
|
user_ids = submissions.map(&:user_id).uniq # hide stream items for submission owners, not instructors
|
|
|
|
# note: unfortunately this will hide items for an instructor if instructor (somehow) has a submission too
|
|
|
|
|
|
|
|
Shard.partition_by_shard(user_ids) do |user_ids_subset|
|
|
|
|
StreamItemInstance.where(:stream_item_id => stream_items, :user_id => user_ids_subset).
|
2013-03-19 23:49:31 +08:00
|
|
|
update_all_with_invalidation(stream_item_contexts, :hidden => true)
|
2012-11-17 06:00:05 +08:00
|
|
|
end
|
2018-05-11 09:01:37 +08:00
|
|
|
|
|
|
|
# Teachers want to hide their submission comments if they mute
|
|
|
|
# the assignment after leaving them.
|
|
|
|
instructor_ids = self.context.instructors.pluck(:id)
|
|
|
|
visible_comment_sub_ids =
|
|
|
|
SubmissionComment.where(hidden: false, submission_id: submission_ids, author_id: instructor_ids).
|
|
|
|
pluck(:submission_id)
|
|
|
|
update_submission_comments_and_count(visible_comment_sub_ids, hidden: true, instructor_ids: instructor_ids) if visible_comment_sub_ids.any?
|
2011-12-11 08:09:40 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Make muting compatible w/ post policies
Allow an assignment to post/unpost an arbitrary set of submissions, and
use this workflow for muting/unmuting. When post policies are enabled,
determine an assignment's muted? status based on whether it has any
unposted submissions (and update it as submissions are posted/unposted).
When the user manually mutes/unmutes an assignment, adjust its post
policy accordingly.
closes GRADE-1875
Test plan:
- For a course with the the Post Policies feature flag enabled:
- Create some assignments to play around with
- Creating an anonymous or moderated assignment (or changing an
existing one) should automatically create an associated
PostPolicy object with post_manually set to true
- Otherwise, a PostPolicy should not automatically be created
- (To check this, you'll need to look at assignment.post_policy
in a console; it's not visible in the UI yet)
- Muting an assignment (from the UI or using mute!) should:
- Save a post_policy for the assignment with post_manually set to
true (if not already set)
- Set posted_at for all active submissions to nil
- Do the usual other stuff like hiding submission comments
- Have no effect if all submissions are already unposted
- Unmuting an assignment (from the UI or using unmute!) should:
- Save a post_policy for the assignment with post_manually set to
false (if not already set)
- Set posted_at for all active submissions to the current date
- Do the usual other stuff like showing submission comments
- Have no effect if all submissions are already posted
- In a Rails console, find an assignment/some submissions to test with
> assignment.post_submissions(submissions: submissions)
- This should post the given submissions (i.e., set posted_at,
show comments, etc.) but no others
> assignment.unpost_submissions(submissions: submissions)
- This should unpost only the given submissions
- Both methods should update the assignment's muted attribute
automatically:
- Muted should be set to true if any active submissions on the
assignment remain unposted, and false if all are posted
- Note: setting the posted_at time on an individual submission
will NOT auto-update the assignment's muted status (as of this
patchset)
- For a course with the the Post Policies feature flag *disabled*:
- Muting/unmuting an assignment should work as usual, and should
*not* attempt to create a post policy on the assignment
- It should, however, still set or unset the posted_at date on
all the assignment's submissions
- In a Rails console:
- The muted? attribute should behave like before (i.e., it should
not be dynamically updated if a subset of submissions is posted
or unposted)
Change-Id: I317dee609fe92cf2832d36bff54511abeb72137c
Reviewed-on: https://gerrit.instructure.com/179361
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Jenkins
QA-Review: Gary Mei <gmei@instructure.com>
Product-Review: Keith Garner <kgarner@instructure.com>
2019-01-26 00:40:32 +08:00
|
|
|
def show_stream_items(submissions:)
|
|
|
|
if submissions.present?
|
|
|
|
submission_ids = submissions.pluck(:id)
|
2013-03-19 23:49:31 +08:00
|
|
|
stream_items = StreamItem.select([:id, :context_type, :context_id]).
|
Make muting compatible w/ post policies
Allow an assignment to post/unpost an arbitrary set of submissions, and
use this workflow for muting/unmuting. When post policies are enabled,
determine an assignment's muted? status based on whether it has any
unposted submissions (and update it as submissions are posted/unposted).
When the user manually mutes/unmutes an assignment, adjust its post
policy accordingly.
closes GRADE-1875
Test plan:
- For a course with the the Post Policies feature flag enabled:
- Create some assignments to play around with
- Creating an anonymous or moderated assignment (or changing an
existing one) should automatically create an associated
PostPolicy object with post_manually set to true
- Otherwise, a PostPolicy should not automatically be created
- (To check this, you'll need to look at assignment.post_policy
in a console; it's not visible in the UI yet)
- Muting an assignment (from the UI or using mute!) should:
- Save a post_policy for the assignment with post_manually set to
true (if not already set)
- Set posted_at for all active submissions to nil
- Do the usual other stuff like hiding submission comments
- Have no effect if all submissions are already unposted
- Unmuting an assignment (from the UI or using unmute!) should:
- Save a post_policy for the assignment with post_manually set to
false (if not already set)
- Set posted_at for all active submissions to the current date
- Do the usual other stuff like showing submission comments
- Have no effect if all submissions are already posted
- In a Rails console, find an assignment/some submissions to test with
> assignment.post_submissions(submissions: submissions)
- This should post the given submissions (i.e., set posted_at,
show comments, etc.) but no others
> assignment.unpost_submissions(submissions: submissions)
- This should unpost only the given submissions
- Both methods should update the assignment's muted attribute
automatically:
- Muted should be set to true if any active submissions on the
assignment remain unposted, and false if all are posted
- Note: setting the posted_at time on an individual submission
will NOT auto-update the assignment's muted status (as of this
patchset)
- For a course with the the Post Policies feature flag *disabled*:
- Muting/unmuting an assignment should work as usual, and should
*not* attempt to create a post policy on the assignment
- It should, however, still set or unset the posted_at date on
all the assignment's submissions
- In a Rails console:
- The muted? attribute should behave like before (i.e., it should
not be dynamically updated if a subset of submissions is posted
or unposted)
Change-Id: I317dee609fe92cf2832d36bff54511abeb72137c
Reviewed-on: https://gerrit.instructure.com/179361
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Jenkins
QA-Review: Gary Mei <gmei@instructure.com>
Product-Review: Keith Garner <kgarner@instructure.com>
2019-01-26 00:40:32 +08:00
|
|
|
where(asset_type: 'Submission', asset_id: submission_ids).
|
|
|
|
preload(:context).to_a
|
2012-11-17 06:00:05 +08:00
|
|
|
stream_item_contexts = stream_items.map { |si| [si.context_type, si.context_id] }
|
|
|
|
associated_shards = stream_items.inject([]) { |result, si| result | si.associated_shards }
|
|
|
|
Shard.with_each_shard(associated_shards) do
|
2013-03-19 23:49:31 +08:00
|
|
|
StreamItemInstance.where(:hidden => true, :stream_item_id => stream_items).
|
|
|
|
update_all_with_invalidation(stream_item_contexts, :hidden => false)
|
2012-11-17 06:00:05 +08:00
|
|
|
end
|
conversation messages for submission comments, fixes #5443
this commit makes submission first-class citizens in conversations. this
means that when submission comments are added/deleted, or assignments are
unmuted, conversations and messages will be updated accordingly
the main impacts in the ui are:
1. submissions can be deleted from conversations. if a new comment is
added, they will reappear
2. submissions factor into the message total for the conversation. each
submission counts as a single message, even if there are multiple
comments
3. submission messages affect unread-ness, and are reflected in the
timestamp and text in the conversation preview
test plan:
1. confirm submissions appear in the appropriate conversations, i.e.
* submissions with no comments should not appear in any conversations
* submissions where there are comments but not by instructors:
* should appear in each instructor's private conversation with the
submitter
* should not appear in the submitter's private conversations with
anyone
* submissions where there are comments by instructors:
* should appear in each commenting instructor's private conversation
with the submitter
* should appear in submitter's private conversations with each
commenting instructor
adding or removing submission comments should update private
conversations accordingly (e.g. when one teacher comments on a
submission, it should be removed from the other teachers' private
conversations with the submitter).
2. for each scenario above where the submission comments are added and
appear in conversations, ensure that the submission as a whole behaves
like a single conversation message, i.e.
* the unread conversations count is incremented and the private
conversation is marked as unread (if it didn't exist or was already
read)
* the latest submission comment and timestamp should be reflected in
the conversation pane on the left side
* you can delete the submission from the conversation. if new comments
are posted on the submission, the submission should reappear in the
conversation (provided it still matches the criteria in 1.). note
that submission can not be forwarded to other conversations.
3. submissions should differ from traditional conversation messages in
that:
* they should not trigger conversation notifications
* they should not create/bump conversation stream items. if a
conversation has non-submission messages, the submission and its
comments should appear in the stream item, but they should not
cause it to jump to the top
migration:
existing submissions/comments will be migrated in, but not necessarily
through a traditional rails migration. to bring in those messages, run
the following from the rails console:
Submission.find_each{ |s| s.create_or_update_conversations!(:migrate) }
Change-Id: I06dcb8728402a6c4c613d445b80432a1f2973b73
Reviewed-on: https://gerrit.instructure.com/8086
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
2012-01-16 23:39:31 +08:00
|
|
|
|
2018-05-11 09:01:37 +08:00
|
|
|
hidden_comment_sub_ids = SubmissionComment.where(hidden: true, submission_id: submission_ids).pluck(:submission_id)
|
|
|
|
update_submission_comments_and_count(hidden_comment_sub_ids, hidden: false) if hidden_comment_sub_ids.any?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_submission_comments_and_count(submission_ids, hidden: false, instructor_ids: nil)
|
2018-12-12 05:04:55 +08:00
|
|
|
update_time = Time.zone.now
|
2018-05-11 09:01:37 +08:00
|
|
|
submission_ids.each_slice(100) do |submission_id_slice|
|
|
|
|
submission_comment_scope = SubmissionComment.where(hidden: !hidden, submission_id: submission_id_slice)
|
|
|
|
submission_comment_scope = submission_comment_scope.where(author_id: instructor_ids) if instructor_ids.present?
|
2018-12-12 05:04:55 +08:00
|
|
|
submission_comment_scope.update_all(hidden: hidden, updated_at: update_time)
|
2018-05-11 09:01:37 +08:00
|
|
|
|
|
|
|
Submission.where(:id => submission_id_slice).
|
|
|
|
update_all(["submission_comments_count = (SELECT COUNT(*) FROM #{SubmissionComment.quoted_table_name} WHERE
|
2017-04-11 21:37:10 +08:00
|
|
|
submissions.id = submission_comments.submission_id AND submission_comments.hidden = ? AND
|
|
|
|
submission_comments.draft IS NOT TRUE AND submission_comments.provisional_grade_id IS NULL)", false])
|
2011-09-15 06:41:56 +08:00
|
|
|
end
|
|
|
|
end
|
Make muting compatible w/ post policies
Allow an assignment to post/unpost an arbitrary set of submissions, and
use this workflow for muting/unmuting. When post policies are enabled,
determine an assignment's muted? status based on whether it has any
unposted submissions (and update it as submissions are posted/unposted).
When the user manually mutes/unmutes an assignment, adjust its post
policy accordingly.
closes GRADE-1875
Test plan:
- For a course with the the Post Policies feature flag enabled:
- Create some assignments to play around with
- Creating an anonymous or moderated assignment (or changing an
existing one) should automatically create an associated
PostPolicy object with post_manually set to true
- Otherwise, a PostPolicy should not automatically be created
- (To check this, you'll need to look at assignment.post_policy
in a console; it's not visible in the UI yet)
- Muting an assignment (from the UI or using mute!) should:
- Save a post_policy for the assignment with post_manually set to
true (if not already set)
- Set posted_at for all active submissions to nil
- Do the usual other stuff like hiding submission comments
- Have no effect if all submissions are already unposted
- Unmuting an assignment (from the UI or using unmute!) should:
- Save a post_policy for the assignment with post_manually set to
false (if not already set)
- Set posted_at for all active submissions to the current date
- Do the usual other stuff like showing submission comments
- Have no effect if all submissions are already posted
- In a Rails console, find an assignment/some submissions to test with
> assignment.post_submissions(submissions: submissions)
- This should post the given submissions (i.e., set posted_at,
show comments, etc.) but no others
> assignment.unpost_submissions(submissions: submissions)
- This should unpost only the given submissions
- Both methods should update the assignment's muted attribute
automatically:
- Muted should be set to true if any active submissions on the
assignment remain unposted, and false if all are posted
- Note: setting the posted_at time on an individual submission
will NOT auto-update the assignment's muted status (as of this
patchset)
- For a course with the the Post Policies feature flag *disabled*:
- Muting/unmuting an assignment should work as usual, and should
*not* attempt to create a post policy on the assignment
- It should, however, still set or unset the posted_at date on
all the assignment's submissions
- In a Rails console:
- The muted? attribute should behave like before (i.e., it should
not be dynamically updated if a subset of submissions is posted
or unposted)
Change-Id: I317dee609fe92cf2832d36bff54511abeb72137c
Reviewed-on: https://gerrit.instructure.com/179361
Reviewed-by: Gary Mei <gmei@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Jenkins
QA-Review: Gary Mei <gmei@instructure.com>
Product-Review: Keith Garner <kgarner@instructure.com>
2019-01-26 00:40:32 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_muted_status!
|
|
|
|
# With post policies active, an assignment is considered "muted" if it has any
|
|
|
|
# unposted submissions.
|
|
|
|
has_unposted_submissions = submissions.active.unposted.exists?
|
|
|
|
update!(muted: has_unposted_submissions) if muted? != has_unposted_submissions
|
|
|
|
end
|
2011-09-15 06:41:56 +08:00
|
|
|
end
|