update content participation on publish/unpublish

when changing an assignment between published and unpublished, the
content participation counts should also be updated. this change also
verifies that deleting/restoring an assignment then publishing the
assignment should also update badge count.

fixes EVAL-2850
flag=visibility_feedback_student_grades_page
flag=assignments_2_student

test plan:
- as teacher, create an assignment and publish
- as teacher, grade assignment for a student
- as student, reload the home tab and check that the badge count on the
  grades tab is set to 1
- as teacher, unpublish the assignment
- as student, reload the home tab and check that the badge count on the
  grades tab is now set to 0 (not there)
- as teacher, publish assignment again
- as student, view badge count on grades tab. it should be set to 1
- as teacher, delete assignment
- as student, view the badge count on grades tab. it should be set to 0
- as teacher, restore assignment from
  canvas.docker/courses/{id}/undelete
- as teacher, publish assignment again
- as student, view the badge count on grades tab. it should be 1 again

Change-Id: I26fc1ca24139e1c64b4ae6a46bb74bfffe84523e
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/309377
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Kai Bjorkman <kbjorkman@instructure.com>
Reviewed-by: Cameron Ray <cameron.ray@instructure.com>
QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
Product-Review: Jody Sailor
This commit is contained in:
Chris Soto 2023-01-23 13:48:42 -07:00 committed by Christopher Soto
parent a97fd5ecbe
commit 86bcd543c9
5 changed files with 49 additions and 3 deletions

View File

@ -601,6 +601,7 @@ class Assignment < ActiveRecord::Base
after_save :start_canvadocs_render, if: :saved_change_to_annotatable_attachment_id?
after_save :update_due_date_smart_alerts, if: :update_cached_due_dates?
after_save :mark_module_progressions_outdated, if: :update_cached_due_dates?
after_save :workflow_change_refresh_content_partication_counts, if: :saved_change_to_workflow_state?
after_commit :schedule_do_auto_peer_review_job_if_automatic_peer_review
@ -1373,6 +1374,11 @@ class Assignment < ActiveRecord::Base
ScheduledSmartAlert.where(context_type: "AssignmentOverride", context_id: assignment_override_ids).destroy_all
end
def workflow_change_refresh_content_partication_counts
trigger_workflow_states = %w[published unpublished]
refresh_course_content_participation_counts if trigger_workflow_states.include?(workflow_state)
end
def refresh_course_content_participation_counts
progress = context.progresses.build(tag: "refresh_content_participation_counts")
progress.save!
@ -1393,7 +1399,6 @@ class Assignment < ActiveRecord::Base
each_submission_type do |submission, _, short_type|
submission.restore(:assignment) if from != short_type && submission
end
refresh_course_content_participation_counts
end
def participants_with_overridden_due_at

View File

@ -87,7 +87,7 @@ class ContentParticipationCount < ActiveRecord::Base
GuardRail.activate(:secondary) do
potential_ids = Rails.cache.fetch_with_batched_keys(["potential_unread_submission_ids", context.global_id].cache_key,
batch_object: user, batched_keys: :submissions) do
batch_object: user, batched_keys: [:submissions, :potential_unread_submission_ids]) do
submission_conditions = sanitize_sql_for_conditions([<<~SQL.squish, user.id, context.class.to_s, context.id])
submissions.user_id = ? AND
assignments.context_type = ? AND

View File

@ -3886,6 +3886,8 @@ class Course < ActiveRecord::Base
end
def refresh_content_participation_counts(_progress)
user_ids = content_participation_counts.pluck(:user_id)
User.clear_cache_keys(user_ids, :potential_unread_submission_ids)
content_participation_counts.each(&:refresh_unread_count)
end

View File

@ -32,7 +32,7 @@ module Canvas
"Account" => %w[account_chain role_overrides global_navigation feature_flags brand_config default_locale
resolved_outcome_proficiency resolved_outcome_calculation_method],
"Course" => %w[account_associations conditional_release],
"User" => %w[enrollments groups account_users todo_list submissions user_services k5_user],
"User" => %w[enrollments groups account_users todo_list submissions user_services k5_user potential_unread_submission_ids],
"Assignment" => %w[availability conditional_release needs_grading],
"Quizzes::Quiz" => %w[availability]
}.freeze

View File

@ -9243,6 +9243,45 @@ describe Assignment do
expect(student_unread_count_counts).to eq 1
end
end
context "when changing workflow_state for an assignment" do
before do
Account.site_admin.enable_feature!(:visibility_feedback_student_grades_page)
end
it "unread count changes between 0 and 1 when going to unpublished and published workflow_state" do
assignment.grade_student(student1, grade: 10, grader: teacher)
expect(student_unread_count_counts).to eq 1
assignment.workflow_state = "unpublished"
assignment.save!
run_jobs
expect(student_unread_count_counts).to eq 0
assignment.workflow_state = "published"
assignment.save!
run_jobs
expect(student_unread_count_counts).to eq 1
end
it "does call refresh_course_content_participation_counts when changing to a trigger workflow_state" do
expect(assignment).to receive(:refresh_course_content_participation_counts).twice
assignment.workflow_state = "unpublished"
assignment.save!
assignment.workflow_state = "published"
assignment.save!
end
it "does not call refresh_course_content_participation_counts when not changing to a trigger workflow_state" do
assignment.workflow_state = "duplicating"
assignment.save!
expect(assignment).to_not receive(:refresh_course_content_participation_counts)
end
it "does not call refresh_course_content_participation_counts when changing something other than workflow_state" do
assignment.title = "New Title"
assignment.save!
expect(assignment).to_not receive(:refresh_course_content_participation_counts)
end
end
end
describe "grade change audit records" do