Add custom variable com.instructure.Observee.sisIds
We're adding a custom variable substitution that returns a string of observee's (students) SIS ids for the current user (observer), in the context of the current course for LTI toll launches. closes INTEROP-5940 flag=none test-plan: * Have an LTI tool installed in your local Canvas at a course level that uses the new custom variable. * Ensure that your current user is enrolled in at least section in the course the tool is installed in. * Launch the tool and ensure that under the custom claims you see the observee ids variable expanded to an array that matches the students your current user is linked in the current course. Change-Id: Ib9d019411b991646633a4c3b7bc33ac159635379 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/249646 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Weston Dransfield <wdransfield@instructure.com> Reviewed-by: Xander Moffatt <xmoffatt@instructure.com> QA-Review: Xander Moffatt <xmoffatt@instructure.com> Product-Review: Karl Lloyd <karl@instructure.com>
This commit is contained in:
parent
236b495375
commit
f907d70909
|
@ -188,6 +188,15 @@ context of the tool launch is within a course.
|
|||
```
|
||||
[ "Section 1", "Section 5", "TA Section"]
|
||||
```
|
||||
## com.instructure.Observee.sisIds
|
||||
returns all observee ids linked to this observer as an String separated by `,`.
|
||||
|
||||
**Availability**: *when launched in a course*
|
||||
**Launch Parameter**: *com_instructure_observee_sis_ids*
|
||||
|
||||
```
|
||||
"A123,B456,..."
|
||||
```
|
||||
## Context.title
|
||||
The title of the context.
|
||||
|
||||
|
|
|
@ -178,6 +178,20 @@ module Lti
|
|||
ENROLLMENT_GUARD,
|
||||
default_name: 'com_instructure_user_section_names'
|
||||
|
||||
# returns all observee ids linked to this observer as an String separated by `,`
|
||||
# @launch_parameter com_instructure_observee_ids
|
||||
# @example
|
||||
# ```
|
||||
# "A123,B456,..."
|
||||
# ```
|
||||
register_expansion 'com.instructure.Observee.sisIds', [],
|
||||
-> do
|
||||
observed_users = ObserverEnrollment.observed_students(@context, @current_user).keys
|
||||
observed_users&.collect { |user| find_sis_user_id_for(user) }&.compact&.join(',')
|
||||
end,
|
||||
COURSE_GUARD,
|
||||
default_name: 'com_instructure_observee_sis_ids'
|
||||
|
||||
# The title of the context
|
||||
# @launch_parameter context_title
|
||||
# @example
|
||||
|
@ -1440,6 +1454,11 @@ module Lti
|
|||
@sis_pseudonym ||= SisPseudonym.for(@current_user, context, type: :trusted, require_sis: false, root_account: @root_account) if @current_user
|
||||
end
|
||||
|
||||
def find_sis_user_id_for(user)
|
||||
context = @enrollment || @context
|
||||
SisPseudonym.for(user, context, type: :trusted, require_sis: false, root_account: @root_account)&.sis_user_id
|
||||
end
|
||||
|
||||
def expand_substring_variables(value)
|
||||
value.to_s.scan(SUBSTRING_REGEX).inject(value) do |v, match|
|
||||
substring = "${#{match}}"
|
||||
|
|
|
@ -115,7 +115,8 @@ module Lti
|
|||
com.instructure.Course.available_canvas_resources
|
||||
com.instructure.Person.pronouns
|
||||
com.instructure.User.observees
|
||||
com.instructure.User.sectionNames)
|
||||
com.instructure.User.sectionNames
|
||||
com.instructure.Observee.sisIds)
|
||||
}
|
||||
|
||||
describe '#supported_capabilities' do
|
||||
|
|
|
@ -1111,6 +1111,59 @@ module Lti
|
|||
end
|
||||
end
|
||||
|
||||
describe '$com.instructure.Observee.sisIds' do
|
||||
subject do
|
||||
exp_hash = { observee_sis_ids: '$com.instructure.Observee.sisIds' }
|
||||
variable_expander.expand_variables!(exp_hash)
|
||||
exp_hash[:observee_sis_ids]
|
||||
end
|
||||
|
||||
let(:student_a) { user_factory }
|
||||
let(:student_b) { user_factory }
|
||||
let(:student_c) { user_factory }
|
||||
let(:observer) { user_factory }
|
||||
let(:variable_expander) { VariableExpander.new(root_account, course, controller, current_user: observer, tool: tool) }
|
||||
let(:context) do
|
||||
c = variable_expander.context
|
||||
c.save!
|
||||
c
|
||||
end
|
||||
|
||||
before do
|
||||
managed_pseudonym(student_a, account: root_account, sis_user_id: 'SIS_A')
|
||||
managed_pseudonym(student_b, account: root_account, sis_user_id: 'SIS_B')
|
||||
|
||||
context.enroll_student(student_a)
|
||||
context.enroll_student(student_b)
|
||||
context.enroll_student(student_c)
|
||||
|
||||
variable_expander.current_user = observer
|
||||
end
|
||||
|
||||
context 'when the current user is observing students in the course context' do
|
||||
before do
|
||||
student_a_enrollment = context.enroll_user(observer, 'ObserverEnrollment')
|
||||
student_a_enrollment.update!(associated_user_id: student_a.id)
|
||||
|
||||
student_b_enrollment = context.enroll_user(observer, 'ObserverEnrollment')
|
||||
student_b_enrollment.update!(associated_user_id: student_b.id)
|
||||
|
||||
student_c_enrollment = context.enroll_user(observer, 'ObserverEnrollment')
|
||||
student_c_enrollment.update!(associated_user_id: student_c.id)
|
||||
end
|
||||
|
||||
it 'return an array of all student that has a SIS IDs' do
|
||||
expect(subject).to eq 'SIS_A,SIS_B'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the current user is not observing students in the course context' do
|
||||
it 'return a empty array of student SIS IDs' do
|
||||
expect(subject).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'context is a course and there is a user' do
|
||||
let(:variable_expander) { VariableExpander.new(root_account, course, controller, current_user: user, tool: tool) }
|
||||
let(:user) { user_factory }
|
||||
|
|
Loading…
Reference in New Issue