diff --git a/doc/api/tools_variable_substitutions.md b/doc/api/tools_variable_substitutions.md index a44effe6e6d..67d4bb97996 100644 --- a/doc/api/tools_variable_substitutions.md +++ b/doc/api/tools_variable_substitutions.md @@ -550,6 +550,15 @@ Returns the full name of the launching user. **Availability**: *when launched by a logged in user* **Launch Parameter**: *lis_person_name_full* +``` +John Doe +``` +## Person.name.display +Returns the display name of the launching user. + +**Availability**: *when launched by a logged in user* +**Launch Parameter**: *person_name_display* + ``` John Doe ``` diff --git a/lib/lti/variable_expander.rb b/lib/lti/variable_expander.rb index 7a1ce89de8b..eacfdb108ee 100644 --- a/lib/lti/variable_expander.rb +++ b/lib/lti/variable_expander.rb @@ -597,6 +597,17 @@ module Lti USER_GUARD, default_name: 'lis_person_name_full' + # Returns the display name of the launching user. + # @launch_parameter lis_person_name_full + # @example + # ``` + # John Doe + # ``` + register_expansion 'Person.name.display', [], + -> { @current_user.short_name }, + USER_GUARD, + default_name: 'person_name_display' + # Returns the last name of the launching user. # @launch_parameter lis_person_name_family # @example diff --git a/spec/lib/lti/capabilities_helper_spec.rb b/spec/lib/lti/capabilities_helper_spec.rb index abafc069c94..dcb80f1ac56 100644 --- a/spec/lib/lti/capabilities_helper_spec.rb +++ b/spec/lib/lti/capabilities_helper_spec.rb @@ -81,6 +81,7 @@ module Lti Person.name.given Person.name.family Person.name.full + Person.name.display Person.sourcedId User.id User.image diff --git a/spec/lib/lti/variable_expander_spec.rb b/spec/lib/lti/variable_expander_spec.rb index 9d94f406e15..8e5c8cf8d0d 100644 --- a/spec/lib/lti/variable_expander_spec.rb +++ b/spec/lib/lti/variable_expander_spec.rb @@ -174,6 +174,7 @@ module Lti Person.name.given Person.name.family Person.name.full + Person.name.display Person.sourcedId User.id User.image @@ -267,6 +268,11 @@ module Lti expanded = variable_expander.enabled_capability_params(enabled_capability) expect(expanded.keys).to include 'lis_person_name_full' end + + it 'includes Person.name.display when in enabled capability' do + expanded = variable_expander.enabled_capability_params(enabled_capability) + expect(expanded.keys).to include 'person_name_display' + end end end @@ -966,6 +972,14 @@ module Lti expect(exp_hash[:test]).to eq 'Uncle Jake' end + it 'has substitution for $Person.name.display' do + user.name = 'Uncle Jake' + user.short_name = 'Unc J' + exp_hash = {test: '$Person.name.display'} + variable_expander.expand_variables!(exp_hash) + expect(exp_hash[:test]).to eq 'Unc J' + end + it 'has substitution for $Person.name.family' do user.name = 'Uncle Jake' exp_hash = {test: '$Person.name.family'}