fix missing policies not updating badge count
add an update so that when a missing policy applicator gives a student a grade for a missing assignment, it will also create a content participation record for the student so that the badge count matches the number of content participation records fixes EVAL-3494 flag=none test plan: - have a course with a missing policy activated that sets a grade for a missing assignment - find a student you will test this with, and act as them and view how many grade notifications they have and the badge count number - try to get this badge count to 0 before starting by viewing all the grades or comments that have not been viewed - if you can't get it to 0 due to an existing error with badge counts, just remember what the badge count was before you move on - create an assignment that is due in the next minute - wait for that assignment's due date to pass - in the rails console, run the missing policy applicator with this command: MissingPolicyApplicator.apply_missing_policies - check the badge count for the student in the course and ensure that it went up by one - you should see a new grade notification (blue dot) for the student in the course for the assignment that you just created and they should have a grade of whatever the missing policy set it to - ensure that viewing this grade by clicking it to go to the submission and then going back to the grades page/refreshing the page updates the badge count by decrementing it by one Change-Id: I3fa1382480f9df0c6ed37b219eebc2289698b867 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/328127 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> Reviewed-by: Kai Bjorkman <kbjorkman@instructure.com> QA-Review: Samuel Lee <samuel.lee@instructure.com> Product-Review: Cameron Ray <cameron.ray@instructure.com>
This commit is contained in:
parent
20ad8df364
commit
9c6763a9fa
|
@ -372,6 +372,21 @@ class Auditors::GradeChange
|
|||
bulk_insert_records(event_records)
|
||||
end
|
||||
|
||||
def self.create_content_participations(plucked_submissions, assignment, unique_users)
|
||||
root_account_id = assignment.root_account_id
|
||||
content_participations = []
|
||||
content_participation_counts = []
|
||||
plucked_submissions.each do |user_id, submission_id, course_id|
|
||||
context_type = course_id ? "Course" : assignment.context_type
|
||||
context_id = course_id || assignment.context_id
|
||||
content_participations << { content_type: "Submission", user_id:, content_id: submission_id, workflow_state: "unread", content_item: "grade", root_account_id:, }
|
||||
content_participation_counts << { content_type: "Submission", context_type:, user_id:, root_account_id:, unread_count: 0, context_id:, }
|
||||
end
|
||||
content_participations.each_slice(1000) { |batch| ContentParticipation.insert_all(batch) }
|
||||
content_participation_counts.each_slice(1000) { |batch| ContentParticipationCount.insert_all(batch) }
|
||||
assignment.course.refresh_content_participation_counts_for_users(unique_users)
|
||||
end
|
||||
|
||||
def self.insert_record(event_record)
|
||||
Auditors::GradeChange::Stream.insert(event_record)
|
||||
end
|
||||
|
|
|
@ -55,6 +55,7 @@ class MissingPolicyApplicator
|
|||
now = Time.zone.now
|
||||
|
||||
GuardRail.activate(:primary) do
|
||||
plucked_submissions = submissions.pluck(:user_id, :id, :course_id)
|
||||
submissions = Submission.active.where(id: submissions)
|
||||
|
||||
submissions.update_all(
|
||||
|
@ -77,8 +78,9 @@ class MissingPolicyApplicator
|
|||
if Account.site_admin.feature_enabled?(:fix_missing_policy_applicator_gradebook_history)
|
||||
Auditors::GradeChange.delay_if_production.bulk_record_submission_events(submissions.reload)
|
||||
end
|
||||
|
||||
assignment.course.recompute_student_scores(submissions.map(&:user_id).uniq)
|
||||
unique_users = submissions.map(&:user_id).uniq
|
||||
Auditors::GradeChange.delay_if_production(strand: "CreateParticipationsForMissingPolicy:#{assignment.root_account.global_id}").create_content_participations(plucked_submissions, assignment, unique_users)
|
||||
assignment.course.recompute_student_scores(unique_users)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -118,6 +118,21 @@ describe MissingPolicyApplicator do
|
|||
expect(submission.grade).to eql "F"
|
||||
end
|
||||
|
||||
describe "content participation" do
|
||||
it "creates a content participation record after applying deductions" do
|
||||
late_policy_missing_enabled
|
||||
create_recent_assignment
|
||||
submission = @course.submissions.first
|
||||
submission.update_columns(score: nil, grade: nil, workflow_state: "unsubmitted")
|
||||
applicator.apply_missing_deductions
|
||||
|
||||
expect(submission.content_participations.count).to eq 1
|
||||
cpc = ContentParticipationCount.where(context_id: submission.course_id, user_id: submission.user_id, content_type: "Submission")
|
||||
expect(cpc.count).to eq 1
|
||||
expect(cpc.first.unread_count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
it 'sets the submission workflow state to "graded"' do
|
||||
late_policy_missing_enabled
|
||||
create_recent_assignment
|
||||
|
@ -435,19 +450,6 @@ describe MissingPolicyApplicator do
|
|||
applicator.apply_missing_deductions
|
||||
end
|
||||
end
|
||||
|
||||
context "when the fix_missing_policy_applicator_gradebook_history flag is not enabled" do
|
||||
before do
|
||||
Account.site_admin.disable_feature!(:fix_missing_policy_applicator_gradebook_history)
|
||||
end
|
||||
|
||||
it "does not queue a delayed job when the applicator marks submissions as missing" do
|
||||
assignment.submissions.update_all(score: nil, grade: nil)
|
||||
expect(Auditors::GradeChange).not_to receive(:delay)
|
||||
|
||||
applicator.apply_missing_deductions
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,8 +40,8 @@ describe Auditors::GradeChange do
|
|||
@sub_account = Account.create!(parent_account: @account)
|
||||
@sub_sub_account = Account.create!(parent_account: @sub_account)
|
||||
|
||||
course_with_teacher(account: @sub_sub_account)
|
||||
student_in_course
|
||||
course_with_teacher(account: @sub_sub_account, active_all: true)
|
||||
student_in_course(active_all: true)
|
||||
|
||||
@assignment = @course.assignments.create!(title: "Assignment", points_possible: 10)
|
||||
@submission = @assignment.grade_student(@student, grade: 8, grader: @teacher).first
|
||||
|
@ -247,4 +247,38 @@ describe Auditors::GradeChange do
|
|||
expect(Auditors::ActiveRecord::GradeChangeRecord.last.score_after).to eq 3.0
|
||||
end
|
||||
end
|
||||
|
||||
describe "create_content_participations" do
|
||||
it "does not create a content participation record if one already exists" do
|
||||
plucked_submissions = [[@student.id, @submission.id, @course.id]]
|
||||
expect(@submission.content_participations.count).to eq 1
|
||||
cpc = ContentParticipationCount.where(context_id: @submission.course_id, user_id: @submission.user_id, content_type: "Submission")
|
||||
expect(cpc.count).to eq 1
|
||||
expect(cpc.first.unread_count).to eq 1
|
||||
@assignment.grade_student(@student, grade: nil, grader: @teacher)
|
||||
@submission.update_columns(score: nil, grade: nil, workflow_state: "unsubmitted")
|
||||
Auditors::GradeChange.create_content_participations(plucked_submissions, @assignment, [@student.id])
|
||||
expect(@submission.content_participations.count).to eq 1
|
||||
end
|
||||
|
||||
it "does not create a duplicate content participation count record if one already exists for the course" do
|
||||
ContentParticipation.mark_all_as_read_for_user(@student, @student.submissions, @course)
|
||||
@submission.update_columns(score: nil, grade: nil, workflow_state: "unsubmitted")
|
||||
plucked_submissions = [[@student.id, @submission.id, @course.id]]
|
||||
Auditors::GradeChange.create_content_participations(plucked_submissions, @assignment, [@student.id])
|
||||
|
||||
cpc = ContentParticipationCount.where(context_id: @submission.course_id, user_id: @submission.user_id, content_type: "Submission")
|
||||
expect(cpc.count).to eq 1
|
||||
|
||||
second_assignment = @course.assignments.create!(title: "Assignment 2", points_possible: 10)
|
||||
second_submission = second_assignment.submissions.first
|
||||
second_submission.update_columns(score: nil, grade: nil, workflow_state: "unsubmitted")
|
||||
plucked_submissions = [[@student.id, second_assignment.submissions.first.id, @course.id]]
|
||||
Auditors::GradeChange.create_content_participations(plucked_submissions, second_assignment, [@student.id])
|
||||
|
||||
expect(second_submission.content_participations.count).to eq 1
|
||||
cpc = ContentParticipationCount.where(context_id: second_submission.course_id, user_id: second_submission.user_id, content_type: "Submission")
|
||||
expect(cpc.count).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue