Add developer key to context external tools

Closes PLAT-3657

Test Plan:
Verify an association between the context_external_tools
table and developer_keys table exists. One developer key can have
many tools.

Verify that a developer key is not required to save a tool and that
a tool is not required to save a developer key.

Change-Id: I129c611104fd656580905a248213df1014c68071
Reviewed-on: https://gerrit.instructure.com/160414
Reviewed-by: Cody Cutrer <cody@instructure.com>
Reviewed-by: August Thornton <august@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Tested-by: Jenkins
Product-Review: Weston Dransfield <wdransfield@instructure.com>
This commit is contained in:
wdransfield 2018-08-10 08:44:03 -06:00 committed by Weston Dransfield
parent 7f606a5a27
commit 4ae2b173aa
5 changed files with 61 additions and 0 deletions

View File

@ -23,6 +23,7 @@ class ContextExternalTool < ActiveRecord::Base
has_many :context_external_tool_placements, :autosave => true
belongs_to :context, polymorphic: [:course, :account]
belongs_to :developer_key
include MasterCourses::Restrictor
restrict_columns :content, [:name, :description]

View File

@ -28,6 +28,7 @@ class DeveloperKey < ActiveRecord::Base
has_many :page_views
has_many :access_tokens, -> { where(:workflow_state => "active") }
has_many :developer_key_account_bindings, inverse_of: :developer_key, dependent: :destroy
has_many :context_external_tools
has_one :tool_consumer_profile, :class_name => 'Lti::ToolConsumerProfile'
serialize :scopes, Array

View File

@ -0,0 +1,27 @@
#
# Copyright (C) 2018 - present 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 <http://www.gnu.org/licenses/>.
#
class AddDeveloperKeyIdToContextExternalTools < ActiveRecord::Migration[5.1]
tag :predeploy
disable_ddl_transaction!
def change
add_column :context_external_tools, :developer_key_id, :integer, limit: 8
add_index :context_external_tools, :developer_key_id, algorithm: :concurrently
end
end

View File

@ -26,6 +26,24 @@ describe ContextExternalTool do
@course.update_attribute(:account, @account)
end
describe 'associations' do
let_once(:developer_key) { DeveloperKey.create! }
let_once(:tool) do
ContextExternalTool.create!(
context: @course,
consumer_key: 'key',
shared_secret: 'secret',
name: 'test tool',
url: 'http://www.tool.com/launch',
developer_key: developer_key
)
end
it 'allows setting the developer key' do
expect(tool.developer_key).to eq developer_key
end
end
describe '#duplicated_in_context?' do
shared_examples_for 'detects duplication in contexts' do
let(:context) { raise 'Override in spec' }

View File

@ -176,6 +176,20 @@ describe DeveloperKey do
developer_key_saved.destroy_permanently!
expect(DeveloperKeyAccountBinding.find_by(id: binding_id)).to be_nil
end
it 'has many context external tools' do
tool = ContextExternalTool.create!(
context: account,
consumer_key: 'key',
shared_secret: 'secret',
name: 'test tool',
url: 'http://www.tool.com/launch',
developer_key: developer_key_saved
)
expect(developer_key_saved.context_external_tools).to match_array [
tool
]
end
end
describe '#account_binding_for' do