add lti_guid include option to account api

to help integration tie LTI launches to canvas accounts

Test Plan:
 * Do an account api call with include[]=lti_guid
 * the lti_guid of the account(s) should be returned

fixes PLAT-938

Change-Id: Ic68f82a19ca3828fe8958e75892d9c16533bae79
Reviewed-on: https://gerrit.instructure.com/47082
QA-Review: August Thornton <august@instructure.com>
Tested-by: Jenkins
Reviewed-by: August Thornton <august@instructure.com>
Product-Review: August Thornton <august@instructure.com>
This commit is contained in:
Bracken Mosbacker 2015-01-13 15:51:44 -07:00
parent 055adb3f3d
commit 3018205bc2
3 changed files with 32 additions and 1 deletions

View File

@ -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

View File

@ -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?

View File

@ -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