Support parents with cross-shard enrollments

closes LS-2750
flag = k5_parent_support

Test plan:
 - Check out the setup steps in ticket LS-2750
 - Visit the dashboard as the observer and expect to see the
   cross-shard user in the dropdown

Change-Id: I9dff318e177e7891a063f4cf4afa860fb38b1280
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/276370
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Nate Armstrong <narmstrong@instructure.com>
QA-Review: Nate Armstrong <narmstrong@instructure.com>
Product-Review: Jackson Howe <jackson.howe@instructure.com>
This commit is contained in:
Jackson Howe 2021-10-20 09:00:24 -06:00
parent 137fd38f3b
commit f0e10a5236
2 changed files with 23 additions and 5 deletions

View File

@ -31,9 +31,9 @@ module ObserverEnrollmentsHelper
def observed_users(user, session, course_id = nil)
return [] unless user
users = Rails.cache.fetch_with_batched_keys(["observed_users", course_id].cache_key, batch_object: user, batched_keys: :enrollments, expires_in: 1.hour) do
users = Rails.cache.fetch_with_batched_keys(["observed_users", course_id].cache_key, batch_object: user, batched_keys: :enrollments, expires_in: 1.day) do
GuardRail.activate(:secondary) do
scope = user.enrollments.active_or_pending
scope = user.enrollments.active_or_pending.shard(user.in_region_associated_shards)
scope = scope.where(course_id: course_id) if course_id
has_own_enrollments = scope.not_of_observer_type.exists?
users = User.where(

View File

@ -171,12 +171,15 @@ describe ObserverEnrollmentsHelper do
context "sharding" do
specs_require_sharding
it "includes and sorts observed users from multiple shards" do
before :once do
@shard2.activate do
@student3 = user_factory(active_all: true, name: "Student 3")
@student3.sortable_name = "0" # before student 1
@student3.save!
end
end
it "includes and sorts observed users from multiple shards" do
@student3.sortable_name = "0" # before student 1
@student3.save!
@course1.enroll_student(@student3)
enroll_observer(@course1, @observer, @student3)
enroll_observer(@course1, @observer, @student1)
@ -186,5 +189,20 @@ describe ObserverEnrollmentsHelper do
expect(users[0][:name]).to eq("Student 3")
expect(users[1][:name]).to eq("Student 1")
end
it "includes observers with observer enrollments in courses on another shard" do
enroll_observer(@course1, @observer, @student1)
@shard2.activate do
account = Account.create!
@course3 = course_factory(active_all: true, account: account)
@course3.enroll_student(@student3)
enroll_observer(@course3, @observer, @student3)
users = observed_users(@observer, nil)
expect(users.length).to be(2)
expect(users[0][:name]).to eq("Student 1")
expect(users[1][:name]).to eq("Student 3")
end
end
end
end