diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 0195e9ae60b..e4739bad92a 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -82,6 +82,11 @@ require 'csv' # "example": "12", # "type": "integer" # }, +# "lti_guid": { +# "description": "The account's identifier that is sent as context_id in LTI launches.", +# "example": "123xyz", +# "type": "string" +# }, # "workflow_state": { # "description": "The state of the account. Can be 'active' or 'deleted'.", # "example": "active", @@ -104,6 +109,12 @@ class AccountsController < ApplicationController # students and even teachers will get an empty list in response, only # account admins can view the accounts that they are in. # + # @argument include[] [String, "lti_guid"|"registration_settings"] + # Array of additional information to include. + # + # "lti_guid":: the 'tool_consumer_instance_guid' that will be sent for this account on LTI launches + # "registration_settings":: returns info about the privacy policy and terms of use + # # @returns [Account] def index respond_to do |format| @@ -117,7 +128,10 @@ class AccountsController < ApplicationController @accounts = [] end ActiveRecord::Associations::Preloader.new(@accounts, :root_account).run - render :json => @accounts.map { |a| account_json(a, @current_user, session, params[:includes] || [], false) } + + # originally had 'includes' instead of 'include' like other endpoints + includes = params[:include] || params[:includes] + render :json => @accounts.map { |a| account_json(a, @current_user, session, includes || [], false) } end end end diff --git a/lib/api/v1/account.rb b/lib/api/v1/account.rb index 29a18af7b59..02c37f171fb 100644 --- a/lib/api/v1/account.rb +++ b/lib/api/v1/account.rb @@ -48,6 +48,7 @@ module Api::V1::Account hash['sis_account_id'] = account.sis_source_id if !account.root_account? && account.root_account.grants_any_right?(user, :read_sis, :manage_sis) hash['sis_import_id'] = account.sis_batch_id if !account.root_account? && account.root_account.grants_right?(user, session, :manage_sis) hash['integration_id'] = account.integration_id if !account.root_account? && account.root_account.grants_any_right?(user, :read_sis, :manage_sis) + hash['lti_guid'] = account.lti_guid if includes.include?('lti_guid') if includes.include?('registration_settings') hash['registration_settings'] = {:login_handle_name => account.login_handle_name} if account.root_account? diff --git a/spec/apis/v1/accounts_api_spec.rb b/spec/apis/v1/accounts_api_spec.rb index 4891349c0ca..b488130de02 100644 --- a/spec/apis/v1/accounts_api_spec.rb +++ b/spec/apis/v1/accounts_api_spec.rb @@ -203,6 +203,22 @@ describe "Accounts API", type: :request do } ) end + + it "should return the lti_guid" do + @a1.lti_guid = 'hey' + @a1.save! + json = api_call(:get, "/api/v1/accounts?include[]=lti_guid", + { :controller => 'accounts', :action => 'index', :format => 'json', :include => ['lti_guid'] }, {}) + expect(json[0]["lti_guid"]).to eq 'hey' + end + + it "should honor deprecated includes parameter" do + @a1.lti_guid = 'hey' + @a1.save! + json = api_call(:get, "/api/v1/accounts?includes[]=lti_guid", + { :controller => 'accounts', :action => 'index', :format => 'json', :includes => ['lti_guid'] }, {}) + expect(json[0]["lti_guid"]).to eq 'hey' + end end describe 'update' do