allow rce editor buttons to work with group contexts

test plan:
* create a group for a course
* add an editor_button configured LTI tool to
 the course or account (such as youtube embed)
* create or edit rce content in the group
 (such as a discussion topic or wiki page)
* the editor button should show up and function

closes #CNVS-2866

Change-Id: Icad2258689565046d5a40d346e1968e8dad6cbdb
Reviewed-on: https://gerrit.instructure.com/51927
Tested-by: Jenkins
Reviewed-by: Nathan Mills <nathanm@instructure.com>
QA-Review: Clare Strong <clare@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2015-04-09 11:30:56 -06:00
parent 13f8256e92
commit 5b8a1875fb
7 changed files with 31 additions and 25 deletions

View File

@ -478,13 +478,11 @@ module ApplicationHelper
end
def editor_buttons
return [] if @context.is_a?(Group)
contexts = []
contexts << @context if @context && @context.respond_to?(:context_external_tools)
contexts += @context.account_chain if @context.respond_to?(:account_chain)
contexts = ContextExternalTool.contexts_to_search(@context)
return [] if contexts.empty?
Rails.cache.fetch((['editor_buttons_for'] + contexts.uniq).cache_key) do
tools = ContextExternalTool.active.having_setting('editor_button').where(contexts.map{|context| "(context_type='#{context.class.base_class.to_s}' AND context_id=#{context.id})"}.join(" OR "))
tools = ContextExternalTool.shard(@context.shard).active.
having_setting('editor_button').polymorphic_where(context: contexts)
tools.sort_by(&:id).map do |tool|
{
:name => tool.label_for(:editor_button, nil),

View File

@ -454,7 +454,6 @@ class ContextExternalTool < ActiveRecord::Base
[]
end
end
private_class_method :contexts_to_search
LOR_TYPES = [:course_home_sub_navigation, :course_settings_sub_navigation, :global_navigation,
:assignment_menu, :file_menu, :discussion_topic_menu, :module_menu, :quiz_menu,
@ -565,14 +564,10 @@ class ContextExternalTool < ActiveRecord::Base
end
end
context = context.context if context.is_a?(Group)
tool = context.context_external_tools.having_setting(type).where(id: id).first
if !tool && context.is_a?(Group)
context = context.context
tool = context.context_external_tools.having_setting(type).where(id: id).first
end
if !tool
tool = ContextExternalTool.having_setting(type).where(context_type: 'Account', context_id: context.account_chain, id: id).first
end
tool ||= ContextExternalTool.having_setting(type).where(context_type: 'Account', context_id: context.account_chain, id: id).first
raise ActiveRecord::RecordNotFound if !tool && raise_error
tool

View File

@ -15,7 +15,7 @@ module Lti
case @canvas_context
when Account
create_account(@canvas_context)
when Course
when Course, Group
create_account(@canvas_context.account)
when User
create_account(@root_account)

View File

@ -22,6 +22,8 @@ module Lti
end
when User
LtiOutbound::LTIUser.new
else
LtiOutbound::LTIContext.new
end
lti_context.consumer_instance = consumer_instance

View File

@ -463,6 +463,14 @@ CanvasRails::Application.routes.draw do
resources :collaborations
get 'calendar' => 'calendars#show2', as: :old_calendar
resources :external_tools do
get :finished
get :resource_selection
collection do
get :retrieve
end
end
end
resources :accounts do

View File

@ -537,7 +537,7 @@ describe ApplicationHelper do
end
describe "editor_buttons" do
it "should return empty hash if in group" do
it "should return hash of tools if in group" do
@course = course_model
@group = @course.groups.create!(:name => "some group")
tool = @course.context_external_tools.new(:name => "bob", :consumer_key => "test", :shared_secret => "secret", :url => "http://example.com")
@ -545,7 +545,7 @@ describe ApplicationHelper do
tool.save!
@context = @group
expect(editor_buttons).to eq([])
expect(editor_buttons).to eq([{:name=>"bob", :id=>tool.id, :url=>"http://example.com", :icon_url=>"http://example.com", :width=>800, :height=>400}])
end
it "should return hash of tools if in course" do

View File

@ -7,7 +7,7 @@ describe "external tool buttons" do
course_with_teacher_logged_in
end
def load_selection_test_tool(element)
def load_selection_test_tool(element, context=@course)
tool = @course.context_external_tools.new(:name => "bob", :consumer_key => "bob", :shared_secret => "bob", :url => "http://www.example.com/ims/lti")
tool.editor_button = {
:url => "http://#{HostUrl.default_host}/selection_test",
@ -15,17 +15,12 @@ describe "external tool buttons" do
:text => "Selection Test"
}
tool.save!
get "/courses/#{@course.id}/discussion_topics"
wait_for_ajaximations
add_button = keep_trying_until do
add_button = f('.btn-primary')
expect(add_button).not_to be_nil
add_button
end
expect_new_page_load { add_button.click }
get "/#{context.class.to_s.downcase.pluralize}/#{context.id}/discussion_topics/new"
wait_for_ajaximations
external_tool_button = f(".mce-instructure_external_tool_button")
expect(external_tool_button).to be_displayed
external_tool_button.click
wait_for_ajax_requests
html = driver.execute_script("return $('textarea[name=message]').editorBox('get_code')")
@ -40,6 +35,14 @@ describe "external tool buttons" do
keep_trying_until { !expect(f("#external_tool_button_dialog")).not_to be_displayed }
end
it "should work with groups" do
group(:context => @course)
load_selection_test_tool("#oembed_link", @group)
html = driver.execute_script("return $('textarea[name=message]').editorBox('get_code')")
expect(html).to match(/ZB8T0193/)
end
it "should allow inserting oembed content from external tool buttons" do
load_selection_test_tool("#oembed_link")