Skip to content

Commit

Permalink
return results from multiple shards in enrollments API
Browse files Browse the repository at this point in the history
test plan:
 - have a student who is enrolled in courses in multiple shards
 - as another user who has permission to view the student's
   enrollments in all shards (i.e., a site admin user, or
   a user with a UserObserver link with the student),
   call /api/v1/users/X/enrollments and verify enrollments
   in all shards are returned

fixes ADMIN-1476

Change-Id: I4b73a7b1f3870f647e968c4b88484d8404402f08
Reviewed-on: https://gerrit.instructure.com/166081
Tested-by: Jenkins
Reviewed-by: Jon Willesen <[email protected]>
QA-Review: Mysti Sadler <[email protected]>
Product-Review: Jeremy Stanley <[email protected]>
  • Loading branch information
jstanley0 committed Oct 1, 2018
1 parent 78328c8 commit 4f00ddd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/enrollments_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def user_index_enrollments
is_approved_parent = user.grants_right?(@current_user, :read_as_parent)
# otherwise check for read_roster rights on all of the requested
# user's accounts
approved_accounts = user.associated_root_accounts.inject([]) do |accounts, ra|
approved_accounts = user.associated_root_accounts.shard(user).inject([]) do |accounts, ra|
accounts << ra.id if is_approved_parent || ra.grants_right?(@current_user, session, :read_roster)
accounts
end
Expand Down
17 changes: 16 additions & 1 deletion spec/apis/v1/enrollments_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@
end

context "when scoped by a user" do
it "returns enrollments from all of a user's associated shards" do
it "returns enrollments from all of the current user's associated shards" do
# create a user on a different shard
@shard1.activate { @user = User.create!(name: 'outofshard') }

Expand All @@ -1774,6 +1774,21 @@
expect(json.first['course_id']).to eq(@course.id)
expect(json.first['user_id']).to eq(@user.global_id)
end

it "returns enrollments from all of another user's associated shards" do
@shard1.activate { @other_course = Course.create! account: Account.create! }
@course.enroll_student(@user, enrollment_state: 'active')
@other_course.enroll_student(@user, enrollment_state: 'active')
@student = @user
@observer = user_factory
@student.linked_observers << @observer
json = api_call_as_user(@observer, :get, "/api/v1/users/#{@student.id}/enrollments",
{ :controller => "enrollments_api", :action => "index", :user_id => @student.to_param,
:format => "json" })
courses = json.map { |el| el['course_id'] }
expect(courses).to include @course.id
expect(courses).to include @other_course.id
end
end
end

Expand Down

0 comments on commit 4f00ddd

Please sign in to comment.