Add sis_user_id support to Outcome Results API
fixes PFS-2345 Test Plan: * perform GET /api/v1/courses/:course_id/outcome_results * in URL param user_ids[], pass in a sis_user_id in format user_ids[]=sis_user_id:1234 * verify results Change-Id: I76c8cca719ffa33863fd3056526c69241ee4fec8 Reviewed-on: https://gerrit.instructure.com/60416 Reviewed-by: John Corrigan <jcorrigan@instructure.com> Tested-by: Jenkins QA-Review: Adam Stone <astone@instructure.com> Product-Review: Nick Nelson <nick@instructure.com>
This commit is contained in:
parent
32e22840e5
commit
4f9917d4fd
|
@ -198,8 +198,9 @@ class OutcomeResultsController < ApplicationController
|
|||
#
|
||||
# @argument user_ids[] [Integer]
|
||||
# If specified, only the users whose ids are given will be included in the
|
||||
# results. it is an error to specify an id for a user who is not a student in
|
||||
# the context
|
||||
# results. SIS ids can be used, prefixed by "sis_user_id:".
|
||||
# It is an error to specify an id for a user who is not a student in
|
||||
# the context.
|
||||
#
|
||||
# @argument outcome_ids[] [Integer]
|
||||
# If specified, only the outcomes whose ids are given will be included in the
|
||||
|
@ -370,7 +371,8 @@ class OutcomeResultsController < ApplicationController
|
|||
|
||||
return true if @context.grants_any_right?(@current_user, session, :manage_grades, :view_all_grades)
|
||||
reject! "users not specified and no access to all grades", :forbidden unless params[:user_ids]
|
||||
user_ids = Api.value_to_array(params[:user_ids]).map(&:to_i).uniq
|
||||
user_id_params = Api.value_to_array(params[:user_ids])
|
||||
user_ids = api_find_all(users_for_outcome_context, user_id_params).map(&:id).uniq
|
||||
enrollments = @context.enrollments.where(user_id: user_ids)
|
||||
enrollment_user_ids = enrollments.map(&:user_id).uniq
|
||||
reject! "specified users not enrolled" unless enrollment_user_ids.length == user_ids.length
|
||||
|
@ -437,10 +439,9 @@ class OutcomeResultsController < ApplicationController
|
|||
|
||||
def require_users
|
||||
reject! "cannot specify both user_ids and section_id" if params[:user_ids] && params[:section_id]
|
||||
|
||||
if params[:user_ids]
|
||||
user_ids = Api.value_to_array(params[:user_ids]).map(&:to_i).uniq
|
||||
@users = users_for_outcome_context.where(id: user_ids).uniq
|
||||
user_ids = Api.value_to_array(params[:user_ids]).uniq
|
||||
@users = api_find_all(users_for_outcome_context, user_ids).uniq
|
||||
reject!( "can only include id's of users in the outcome context") if @users.count != user_ids.count
|
||||
elsif params[:section_id]
|
||||
@section = @context.course_sections.where(id: params[:section_id].to_i).first
|
||||
|
@ -448,7 +449,7 @@ class OutcomeResultsController < ApplicationController
|
|||
@users = @section.students
|
||||
end
|
||||
@users ||= users_for_outcome_context
|
||||
@users = @users.order(:id)
|
||||
@users.sort! {|a,b| a.id <=> b.id}
|
||||
end
|
||||
|
||||
def users_for_outcome_context
|
||||
|
|
|
@ -293,6 +293,37 @@ describe "Outcome Results API", type: :request do
|
|||
expect(json['linked'].keys.sort).to eq %w(users)
|
||||
expect(json['linked']['users'].size).to eq 2
|
||||
end
|
||||
|
||||
it "can require_outcome_context with sis_user_ids" do
|
||||
@user = @student
|
||||
pseudonym = pseudonym_model
|
||||
pseudonym.user_id = @student.id
|
||||
pseudonym.sis_user_id = '123'
|
||||
pseudonym.save
|
||||
api_call(:get, outcome_results_url(outcome_course, user_ids: "sis_user_id:123", include: ['users']),
|
||||
controller: 'outcome_results', action: 'index', format: 'json', course_id: outcome_course.id.to_s,
|
||||
user_ids: "sis_user_id:123", include: ['users'])
|
||||
json = JSON.parse(response.body)
|
||||
expect(json['linked']['users'][0]['id'].to_i).to eq @student.id
|
||||
end
|
||||
|
||||
it "can take sis_user_ids" do
|
||||
student_ids = outcome_students[0..1].map(&:id).map(&:to_s)
|
||||
sis_id_student = outcome_students[2]
|
||||
pseudonym = pseudonym_model
|
||||
pseudonym.user_id = sis_id_student.id
|
||||
pseudonym.sis_user_id = '123'
|
||||
pseudonym.save
|
||||
student_ids << "sis_user_id:123"
|
||||
student_id_str = student_ids.join(',')
|
||||
@user = @teacher
|
||||
api_call(:get, outcome_rollups_url(outcome_course, user_ids: student_id_str, include: ['users']),
|
||||
controller: 'outcome_results', action: 'rollups', format: 'json', course_id: outcome_course.id.to_s,
|
||||
user_ids: student_id_str, include: ['users'])
|
||||
json = JSON.parse(response.body)
|
||||
expect(json['linked']['users'].size).to eq 3
|
||||
expect(json['linked']['users'][2]['id'].to_i).to eq sis_id_student.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "section_id parameter" do
|
||||
|
|
Loading…
Reference in New Issue