diff --git a/app/models/account.rb b/app/models/account.rb index 41c3dacc25b..d9edeba4a6b 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -248,8 +248,9 @@ class Account < ActiveRecord::Base def ensure_defaults self.uuid ||= AutoHandle.generate_securish_uuid + self.lti_guid ||= self.uuid if self.respond_to?(:lti_guid) end - + def verify_unique_sis_source_id return true unless self.sis_source_id if self.root_account? diff --git a/db/migrate/20130310212252_add_lti_account_guid.rb b/db/migrate/20130310212252_add_lti_account_guid.rb new file mode 100644 index 00000000000..d7944776cb9 --- /dev/null +++ b/db/migrate/20130310212252_add_lti_account_guid.rb @@ -0,0 +1,11 @@ +class AddLtiAccountGuid < ActiveRecord::Migration + tag :predeploy + + def self.up + add_column :accounts, :lti_guid, :string + end + + def self.down + remove_column :accounts, :lti_guid, :string + end +end diff --git a/db/migrate/20130310213118_generate_old_account_opaque_i_ds.rb b/db/migrate/20130310213118_generate_old_account_opaque_i_ds.rb new file mode 100644 index 00000000000..ae1615c6014 --- /dev/null +++ b/db/migrate/20130310213118_generate_old_account_opaque_i_ds.rb @@ -0,0 +1,9 @@ +class GenerateOldAccountOpaqueIDs < ActiveRecord::Migration + tag :postdeploy + + def self.up + # Set all the root account opaque ids to their old value so that LTI + # integrations won't break + DataFixup::SetAccountLtiOpaqueIds.send_later_if_production(:run) + end +end diff --git a/lib/basic_lti.rb b/lib/basic_lti.rb index d9587706109..9d2ec41b73a 100644 --- a/lib/basic_lti.rb +++ b/lib/basic_lti.rb @@ -127,7 +127,7 @@ module BasicLTI hash['launch_presentation_height'] = 400 hash['launch_presentation_return_url'] = return_url root_context = (context.respond_to?(:root_account) && context.root_account) || context - hash['tool_consumer_instance_guid'] = root_context.uuid + hash['tool_consumer_instance_guid'] = root_context.respond_to?(:lti_guid) ? root_context.lti_guid : root_context.uuid hash['tool_consumer_instance_name'] = root_context.name hash['tool_consumer_instance_contact_email'] = HostUrl.outgoing_email_address # TODO: find a better email address to use here hash['tool_consumer_info_product_family_code'] = 'canvas' diff --git a/lib/data_fixup/set_account_lti_opaque_ids.rb b/lib/data_fixup/set_account_lti_opaque_ids.rb new file mode 100644 index 00000000000..feb53f577a3 --- /dev/null +++ b/lib/data_fixup/set_account_lti_opaque_ids.rb @@ -0,0 +1,10 @@ +module DataFixup::SetAccountLtiOpaqueIds + + def self.run + Account.root_accounts.each do |root| + root.lti_guid = "#{root.opaque_identifier(:asset_string)}.#{HostUrl.context_host(root)}" + root.save! + end + end + +end diff --git a/spec/migrations/set_account_lti_opaque_ids_spec.rb b/spec/migrations/set_account_lti_opaque_ids_spec.rb new file mode 100644 index 00000000000..8141494e603 --- /dev/null +++ b/spec/migrations/set_account_lti_opaque_ids_spec.rb @@ -0,0 +1,34 @@ +# +# Copyright (C) 2012 Instructure, Inc. +# +# This file is part of Canvas. +# +# Canvas is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, version 3 of the License. +# +# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program. If not, see . +# + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') +require 'lib/data_fixup/set_account_lti_opaque_ids.rb' + +describe 'DataFixup::SetAccountLtiOpaqueIds' do + describe "up" do + it "should work" do + root_account = Account.default + root_account.lti_guid.should == root_account.uuid + + DataFixup::SetAccountLtiOpaqueIds.run + + root_account.reload + root_account.lti_guid.should_not == root_account.uuid + end + end +end