don't rename external tools when the tag is renamed
Other asset types (like assignments, wiki pages and files) have a required linking between the name of the asset and the name of the tag. This is for consistency's sake. However, it doesn't make sense to enforce this kind of policy for external tools, since tools can be configured at the account level, and instructors shouldn't have the ability to rename tools somewhere up the chain. This change disconnects external tools from tags linking to those external tools. fixed #6170 testplan: - configure an external tool - add an external tool to a course module - rename the link to something other than the tool's name - check to make sure the tool's name didn't also change - configure an external tool - add an external tool to a course module - rename the tool - check to make sure the link's name didn't also change - add an assignment to a course module - rename the link in the module - check to make sure the assignment's name also changed - add an assignment to a course module - rename the assignment - check to make sure the module link's name also changed Change-Id: I2291b4ca0ee2c83da1dd9a81bc46eb05d1925982 Reviewed-on: https://gerrit.instructure.com/6641 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: JT Olds <jt@instructure.com>
This commit is contained in:
parent
7efd4c62b2
commit
28c9895295
|
@ -35,7 +35,7 @@ class ContentTag < ActiveRecord::Base
|
|||
after_save :touch_context_if_learning_outcome
|
||||
|
||||
attr_accessible :learning_outcome, :context, :tag_type, :mastery_score, :rubric_association, :content_asset_string, :content, :title, :indent, :position, :url, :new_tab
|
||||
|
||||
|
||||
|
||||
set_policy do
|
||||
given {|user, session| self.context && self.context.grants_right?(user, session, :manage_content)}
|
||||
|
@ -145,6 +145,7 @@ class ContentTag < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def update_asset_name!
|
||||
return if !self.sync_title_to_asset_title?
|
||||
correct_context = self.content && self.content.respond_to?(:context) && self.content.context == self.context
|
||||
correct_context ||= self.context && self.content.is_a?(WikiPage) && self.content.wiki && self.content.wiki.wiki_namespaces.length == 1 && self.content.wiki.wiki_namespaces.map(&:context_code).include?(self.context_code)
|
||||
if correct_context
|
||||
|
@ -178,7 +179,7 @@ class ContentTag < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.update_for(asset)
|
||||
tags = ContentTag.find(:all, :conditions => ['content_id = ? AND content_type = ?', asset.id, asset.class.to_s], :select => 'id, tag_type, context_module_id')
|
||||
tags = ContentTag.find(:all, :conditions => ['content_id = ? AND content_type = ?', asset.id, asset.class.to_s], :select => 'id, tag_type, content_type, context_module_id')
|
||||
tag_ids = tags.select{|t| t.sync_title_to_asset_title? }.map(&:id)
|
||||
module_ids = tags.select{|t| t.context_module_id }.map(&:context_module_id)
|
||||
attr_hash = {:updated_at => Time.now.utc}
|
||||
|
@ -191,7 +192,7 @@ class ContentTag < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def sync_title_to_asset_title?
|
||||
self.tag_type != "learning_outcome_association"
|
||||
self.tag_type != "learning_outcome_association" && self.content_type != 'ContextExternalTool'
|
||||
end
|
||||
|
||||
def context_module_action(user, action, points=nil)
|
||||
|
|
|
@ -87,4 +87,76 @@ describe ContentTag do
|
|||
tags.should_not be_empty
|
||||
tags.any?{ |t| t.id == tag.id }.should be_true
|
||||
end
|
||||
|
||||
it "should not rename the linked external tool if the tag is renamed" do
|
||||
course
|
||||
@tool = @course.context_external_tools.create!(:name => "new tool", :consumer_key => "key", :shared_secret => "secret", :domain => 'example.com', :custom_fields => {'a' => '1', 'b' => '2'})
|
||||
@module = @course.context_modules.create!(:name => "module")
|
||||
@tag = @module.add_item({
|
||||
:type => 'context_external_tool',
|
||||
:title => 'Example',
|
||||
:url => 'http://www.example.com',
|
||||
:new_tab => '0'
|
||||
})
|
||||
@tag.update_asset_name!
|
||||
@tool.reload
|
||||
@tool.name.should == "new tool"
|
||||
@tag.reload
|
||||
@tag.title.should == "Example"
|
||||
end
|
||||
|
||||
it "should not rename the tag if the linked external tool is renamed" do
|
||||
course
|
||||
@tool = @course.context_external_tools.create!(:name => "new tool", :consumer_key => "key", :shared_secret => "secret", :domain => 'example.com', :custom_fields => {'a' => '1', 'b' => '2'})
|
||||
@module = @course.context_modules.create!(:name => "module")
|
||||
@tag = @module.add_item({
|
||||
:type => 'context_external_tool',
|
||||
:title => 'Example',
|
||||
:url => 'http://www.example.com',
|
||||
:new_tab => '0'
|
||||
})
|
||||
ContentTag.update_for(@tool)
|
||||
@tool.reload
|
||||
@tool.name.should == "new tool"
|
||||
@tag.reload
|
||||
@tag.title.should == "Example"
|
||||
end
|
||||
|
||||
it "should rename the linked assignment if the tag is renamed" do
|
||||
course
|
||||
@assignment = @course.assignments.create!(:title => "some assignment")
|
||||
@module = @course.context_modules.create!(:name => "module")
|
||||
@tag = @module.add_item({
|
||||
:type => 'assignment',
|
||||
:title => 'some assignment (renamed)',
|
||||
:id => @assignment.id
|
||||
})
|
||||
@tag.update_asset_name!
|
||||
@tag.reload
|
||||
@tag.title.should == 'some assignment (renamed)'
|
||||
@assignment.reload
|
||||
@assignment.title.should == 'some assignment (renamed)'
|
||||
end
|
||||
|
||||
it "should rename the tag if the linked assignment is renamed" do
|
||||
course
|
||||
@assignment = @course.assignments.create!(:title => "some assignment")
|
||||
@module = @course.context_modules.create!(:name => "module")
|
||||
@tag = @module.add_item({
|
||||
:type => 'assignment',
|
||||
:title => 'some assignment',
|
||||
:id => @assignment.id
|
||||
})
|
||||
@tag.reload
|
||||
@tag.title.should == 'some assignment'
|
||||
@assignment.reload
|
||||
@assignment.title.should == 'some assignment'
|
||||
@assignment.title = "some assignment (renamed)"
|
||||
@assignment.save!
|
||||
ContentTag.update_for(@assignment)
|
||||
@tag.reload
|
||||
@tag.title.should == 'some assignment (renamed)'
|
||||
@assignment.reload
|
||||
@assignment.title.should == 'some assignment (renamed)'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue