convert account users index roles scope query to AR syntax

refs FOO-2931
flag = none

Test plan:
• Exercise both /accounts/1/users & /accounts/self api
  index actions and verify pagination works as expected
  (now /accounts/1/users will be populated with the last page
   since we compute the value and our UI sets it)

Change-Id: Ica92e0d1fab189e395d61046d846addba2b34e7d
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/299014
Reviewed-by: Ben Rinaca <brinaca@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Product-Review: August Thornton <august@instructure.com>
This commit is contained in:
August Thornton 2022-08-18 10:20:59 -06:00
parent 766a93bba5
commit fe29dd53b1
1 changed files with 3 additions and 8 deletions

View File

@ -127,14 +127,9 @@ module UserSearch
end
users_scope =
if context.is_a?(Account)
users_scope.where(
"users.id IN (
SELECT e.user_id
FROM #{Enrollment.quoted_table_name} e
WHERE e.role_id=?
AND e.workflow_state NOT IN ('rejected', 'inactive', 'deleted')
)", role_ids
)
users_scope.where(id: Enrollment.select(:user_id)
.where.not(enrollments: { workflow_state: %i[rejected inactive deleted] })
.where(role_id: role_ids))
else
users_scope.where(enrollments: { role_id: role_ids }).distinct
end