Permalink
Browse files

copy missed course settings on course copy

The settings for the course grading scheme, hiding the
final grade, and the storage quota weren't being copied.

Test Plan:
 * On course settings increase file storage limit, set a course grading scheme, and select option to hide totals in student grades summary
 * Copy course, make sure option to copy settings is selected
 * On new course, check that all properties are set

closes #8541

Change-Id: I3cb9b84b425412412e04eddf8a8a8448970e9d5b
Reviewed-on: https://gerrit.instructure.com/11078
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
  • Loading branch information...
1 parent e8d6b9e commit f879b3b51595737976ec56f28ec1ea2d36f7f3d1 @bracken bracken committed May 29, 2012
View
@@ -1749,7 +1749,7 @@ def import_from_migration(data, params, migration)
WikiPage.process_migration_course_outline(data, migration);migration.fast_update_progress(95)
if !migration.copy_options || migration.is_set?(migration.copy_options[:everything]) || migration.is_set?(migration.copy_options[:all_course_settings])
- import_settings_from_migration(data); migration.fast_update_progress(96)
+ import_settings_from_migration(data, migration); migration.fast_update_progress(96)
end
begin
@@ -1802,18 +1802,38 @@ def import_from_migration(data, params, migration)
attr_accessor :imported_migration_items, :full_migration_hash, :external_url_hash, :content_migration
attr_accessor :folder_name_lookups, :attachment_path_id_lookup, :assignment_group_no_drop_assignments
- def import_settings_from_migration(data)
+ def import_settings_from_migration(data, migration)
return unless data[:course]
settings = data[:course]
self.syllabus_body = ImportedHtmlConverter.convert(settings[:syllabus_body], self) if settings[:syllabus_body]
if settings[:tab_configuration] && settings[:tab_configuration].is_a?(Array)
self.tab_configuration = settings[:tab_configuration]
end
+ if settings[:storage_quota] && ( migration.for_course_copy? || self.account.grants_right?(migration.user, nil, :manage_courses))
+ self.storage_quota = settings[:storage_quota]
+ end
+ self.settings[:hide_final_grade] = !!settings[:hide_final_grade] unless settings[:hide_final_grade].nil?
atts = Course.clonable_attributes
atts -= Canvas::Migration::MigratorHelper::COURSE_NO_COPY_ATTS
settings.slice(*atts.map(&:to_s)).each do |key, val|
self.send("#{key}=", val)
end
+ if settings[:grading_standard_enabled]
+ self.grading_standard_enabled = true
+ if settings[:grading_standard_identifier_ref]
+ if gs = self.grading_standards.find_by_migration_id(settings[:grading_standard_identifier_ref])
+ self.grading_standard = gs
+ else
+ migration.add_warning("Couldn't find copied grading standard for the course.")
+ end
+ elsif settings[:grading_standard_id]
+ if gs = GradingStandard.sorted_standards_for(self).find{|s|s.id == settings[:grading_standard_id]}
+ self.grading_standard = gs
+ else
+ migration.add_warning("Couldn't find account grading standard for the course.")
+ end
+ end
+ end
end
def add_migration_warning(message, exception='')
@@ -95,9 +95,19 @@ def create_course_settings(migration_id, document=nil)
end
atts = Course.clonable_attributes
atts -= Canvas::Migration::MigratorHelper::COURSE_NO_COPY_ATTS
+ atts << :grading_standard_enabled
+ atts << :storage_quota
atts.each do |att|
c.tag!(att, @course.send(att)) unless @course.send(att).nil? || @course.send(att) == ''
end
+ c.hide_final_grade @course.settings[:hide_final_grade] unless @course.settings[:hide_final_grade].nil?
+ if @course.grading_standard
+ if @course.grading_standard.context_type == "Account"
+ c.grading_standard_id @course.grading_standard.id
+ else
+ c.grading_standard_identifier_ref create_key(@course.grading_standard)
+ end
+ end
end
course_file.close if course_file
rel_path
@@ -52,22 +52,25 @@ def convert_course_settings(doc)
['title', 'course_code', 'hashtag', 'default_wiki_editing_roles',
'turnitin_comments', 'default_view', 'license', 'locale',
- 'group_weighting_scheme'].each do |string_type|
+ 'group_weighting_scheme', 'storage_quota', 'grading_standard_identifier_ref'].each do |string_type|
val = get_node_val(doc, string_type)
course[string_type] = val unless val.nil?
end
['is_public', 'indexed', 'publish_grades_immediately', 'allow_student_wiki_edits',
'allow_student_assignment_edits', 'show_public_context_messages',
'allow_student_forum_attachments', 'allow_student_organized_groups',
'show_all_discussion_entries', 'open_enrollment', 'allow_wiki_comments',
- 'self_enrollment'].each do |bool_val|
+ 'self_enrollment', 'hide_final_grade', 'grading_standard_enabled'].each do |bool_val|
val = get_bool_val(doc, bool_val)
course[bool_val] = val unless val.nil?
end
['start_at', 'conclude_at'].each do |date_type|
val = get_time_val(doc, date_type)
course[date_type] = val unless val.nil?
end
+ if val = get_int_val(doc, 'grading_standard_id')
+ course['grading_standard_id'] = val
+ end
if nav = get_node_val(doc, 'tab_configuration')
begin
nav = JSON.parse(nav)
@@ -27,6 +27,11 @@
<xs:element name="self_enrollment" type="xs:boolean" minOccurs="0"/>
<xs:element name="turnitin_comments" type="xs:string" minOccurs="0"/>
<xs:element name="locale" type="xs:string" minOccurs="0"/>
+ <xs:element name="hide_final_grade" type="xs:boolean" minOccurs="0"/>
+ <xs:element name="grading_standard_enabled" type="xs:boolean" minOccurs="0"/>
+ <xs:element name="grading_standard_identifier_ref" type="xs:string" minOccurs="0"/>
+ <xs:element name="grading_standard_id" type="xs:integer" minOccurs="0"/>
+ <xs:element name="storage_quota" type="xs:float" minOccurs="0"/>
<xs:element name="default_view" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
@@ -20,70 +20,6 @@
@copy_to.content_migration = @migration
end
- it "should import course settings" do
- #set all the possible values to non-default values
- @copy_from.start_at = 5.minutes.ago
- @copy_from.conclude_at = 1.month.from_now
- @copy_from.is_public = false
- @copy_from.name = "haha copy from test &amp;"
- @copy_from.course_code = 'something funny'
- @copy_from.publish_grades_immediately = false
- @copy_from.allow_student_wiki_edits = true
- @copy_from.allow_student_assignment_edits = true
- @copy_from.hashtag = 'oi'
- @copy_from.show_public_context_messages = false
- @copy_from.allow_student_forum_attachments = false
- @copy_from.default_wiki_editing_roles = 'teachers'
- @copy_from.allow_student_organized_groups = false
- @copy_from.default_view = 'modules'
- @copy_from.show_all_discussion_entries = false
- @copy_from.open_enrollment = true
- @copy_from.storage_quota = 444
- @copy_from.allow_wiki_comments = true
- @copy_from.turnitin_comments = "Don't plagiarize"
- @copy_from.self_enrollment = true
- @copy_from.license = "cc_by_nc_nd"
- @copy_from.locale = "es"
- @copy_from.tab_configuration = [{"id"=>0}, {"id"=>14}, {"id"=>8}, {"id"=>5}, {"id"=>6}, {"id"=>2}, {"id"=>3, "hidden"=>true}]
- @copy_from.save!
-
- body_with_link = %{<p>Watup? <strong>eh?</strong><a href="/courses/%s/assignments">Assignments</a></p>
-<div>
- <div><img src="http://www.instructure.com/images/header-logo.png"></div>
- <div><img src="http://www.instructure.com/images/header-logo.png"></div>
-</div>}
- @copy_from.syllabus_body = body_with_link % @copy_from.id
-
- #export to xml
- builder = Builder::XmlMarkup.new(:indent=>2)
- @resource.create_course_settings("1", builder)
- syllabus = StringIO.new
- @resource.create_syllabus(syllabus)
- #convert to json
- doc = Nokogiri::XML(builder.target!)
- hash = @converter.convert_course_settings(doc)
- syl_doc = Nokogiri::HTML(syllabus.string)
- hash[:syllabus_body] = @converter.convert_syllabus(syl_doc)
- #import json into new course
- hash = hash.with_indifferent_access
- @copy_to.import_settings_from_migration({:course=>hash})
- @copy_to.save!
-
- #compare settings
- @copy_to.conclude_at.should == nil
- @copy_to.start_at.should == nil
- @copy_to.syllabus_body.should == (body_with_link % @copy_to.id)
- @copy_to.storage_quota.should_not == @copy_from.storage_quota
- @copy_to.name.should == 'alt name'
- @copy_to.course_code.should == 'alt name'
- atts = Course.clonable_attributes
- atts -= Canvas::Migration::MigratorHelper::COURSE_NO_COPY_ATTS
- atts.each do |att|
- @copy_to.send(att).should == @copy_from.send(att)
- end
- @copy_to.tab_configuration.should == @copy_from.tab_configuration
- end
-
it "should import assignment groups" do
ag1 = @copy_from.assignment_groups.new
ag1.name = "Boring assignments"
@@ -25,7 +25,7 @@
course_with_teacher(:course_name => "from course", :active_all => true)
@copy_from = @course
- course_with_teacher(:user => @user, :course_name => "to course")
+ course_with_teacher(:user => @user, :course_name => "tocourse", :course_code => "tocourse")
@copy_to = @course
@cm = ContentMigration.new(:context => @copy_to, :user => @user, :source_course => @copy_from, :copy_options => {:everything => "1"})
@@ -88,17 +88,98 @@ def run_course_copy(warnings=[])
@copy_to.syllabus_body.should match(/\/courses\/#{@copy_to.id}\/discussion_topics\/#{new_topic.id}/)
end
+ def make_grading_standard(context)
+ gs = context.grading_standards.new
+ gs.title = "Standard eh"
+ gs.data = [["A", 0.93], ["A-", 0.89], ["B+", 0.85], ["B", 0.83], ["B!-", 0.80], ["C+", 0.77], ["C", 0.74], ["C-", 0.70], ["D+", 0.67], ["D", 0.64], ["D-", 0.61], ["F", 0]]
+ gs.save!
+ gs
+ end
it "should copy course attributes" do
- @copy_from.tab_configuration = [{"id"=>0}, {"id"=>14}, {"id"=>8}, {"id"=>5}, {"id"=>6}, {"id"=>2}, {"id"=>3, "hidden"=>true}]
+ #set all the possible values to non-default values
+ @copy_from.start_at = 5.minutes.ago
+ @copy_from.conclude_at = 1.month.from_now
+ @copy_from.is_public = false
+ @copy_from.name = "haha copy from test &amp;"
+ @copy_from.course_code = 'something funny'
+ @copy_from.publish_grades_immediately = false
+ @copy_from.allow_student_wiki_edits = true
+ @copy_from.allow_student_assignment_edits = true
+ @copy_from.hashtag = 'oi'
+ @copy_from.show_public_context_messages = false
+ @copy_from.allow_student_forum_attachments = false
+ @copy_from.default_wiki_editing_roles = 'teachers'
+ @copy_from.allow_student_organized_groups = false
+ @copy_from.default_view = 'modules'
+ @copy_from.show_all_discussion_entries = false
+ @copy_from.open_enrollment = true
+ @copy_from.storage_quota = 444
+ @copy_from.allow_wiki_comments = true
+ @copy_from.turnitin_comments = "Don't plagiarize"
+ @copy_from.self_enrollment = true
+ @copy_from.license = "cc_by_nc_nd"
@copy_from.locale = "es"
- @copy_from.save
+ @copy_from.tab_configuration = [{"id"=>0}, {"id"=>14}, {"id"=>8}, {"id"=>5}, {"id"=>6}, {"id"=>2}, {"id"=>3, "hidden"=>true}]
+ @copy_from.settings[:hide_final_grade] = true
+ gs = make_grading_standard(@copy_from)
+ @copy_from.grading_standard = gs
+ @copy_from.grading_standard_enabled = true
+ @copy_from.save!
+
+ body_with_link = %{<p>Watup? <strong>eh?</strong><a href="/courses/%s/assignments">Assignments</a></p>
+ <div>
+ <div><img src="http://www.instructure.com/images/header-logo.png"></div>
+ <div><img src="http://www.instructure.com/images/header-logo.png"></div>
+ </div>}
+ @copy_from.syllabus_body = body_with_link % @copy_from.id
run_course_copy
- @copy_to.locale.should == 'es'
+ #compare settings
+ @copy_to.conclude_at.should == nil
+ @copy_to.start_at.should == nil
+ @copy_to.syllabus_body.should == (body_with_link % @copy_to.id)
+ @copy_to.storage_quota.should == 444
+ @copy_to.settings[:hide_final_grade].should == true
+ @copy_to.grading_standard_enabled.should == true
+ gs_2 = @copy_to.grading_standards.find_by_migration_id(mig_id(gs))
+ gs_2.data.should == gs.data
+ @copy_to.grading_standard.should == gs_2
+ @copy_to.name.should == "tocourse"
+ @copy_to.course_code.should == "tocourse"
+ atts = Course.clonable_attributes
+ atts -= Canvas::Migration::MigratorHelper::COURSE_NO_COPY_ATTS
+ atts.each do |att|
+ @copy_to.send(att).should == @copy_from.send(att)
+ end
@copy_to.tab_configuration.should == @copy_from.tab_configuration
+ end
+
+ it "should retain reference to account grading standard" do
+ gs = make_grading_standard(@copy_from.root_account)
+ @copy_from.grading_standard = gs
+ @copy_from.grading_standard_enabled = true
+ @copy_from.save!
+
+ run_course_copy
+
+ @copy_to.grading_standard.should == gs
+ end
+
+ it "should create a warning if an account grading standard can't be found" do
+ gs = make_grading_standard(@copy_from.root_account)
+ @copy_from.grading_standard = gs
+ @copy_from.grading_standard_enabled = true
+ @copy_from.save!
+
+ gs.delete
+
+ run_course_copy(["Couldn't find account grading standard for the course."])
+
+ @copy_to.grading_standard.should == nil
end
+
it "should copy external tools" do
tool_from = @copy_from.context_external_tools.create!(:name => "new tool", :consumer_key => "key", :shared_secret => "secret", :domain => 'example.com', :custom_fields => {'a' => '1', 'b' => '2'})
tool_from.settings[:course_navigation] = {:url => "http://www.example.com", :text => "Example URL"}
@@ -600,7 +681,7 @@ def create_rubric_asmnt
@copy_to.syllabus_body.should == @copy_from.syllabus_body.gsub("/courses/#{@copy_from.id}/file_contents/course%20files",'')
end
- it "should included implied files for course exports" do
+ it "should include implied files for course exports" do
att = Attachment.create!(:filename => 'first.png', :uploaded_data => StringIO.new('ohai'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from)
att2 = Attachment.create!(:filename => 'second.jpg', :uploaded_data => StringIO.new('ohais'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from)
att3 = Attachment.create!(:filename => 'third.jpg', :uploaded_data => StringIO.new('3333'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from)
@@ -2518,6 +2518,34 @@ def new_exernal_tool(context)
@course.course_imports.first.update_attribute(:workflow_state, 'failed')
@course.should_not have_open_course_imports
end
+
+ describe "setting storage quota" do
+ before do
+ course_with_teacher
+ @course.storage_quota = 1
+ @cm = ContentMigration.new(:context => @course, :user => @user, :copy_options => {:everything => "1"})
+ @cm.user = @user
+ @cm.save!
+ end
+
+ it "should not adjust for unauthorized user" do
+ @course.import_settings_from_migration({:course=>{:storage_quota => 4}}, @cm)
+ @course.storage_quota.should == 1
+ end
+
+ it "should adjust for authorized user" do
+ account_admin_user(:user => @user)
+ @course.import_settings_from_migration({:course=>{:storage_quota => 4}}, @cm)
+ @course.storage_quota.should == 4
+ end
+
+ it "should be set for course copy" do
+ @cm.source_course = @course
+ @course.import_settings_from_migration({:course=>{:storage_quota => 4}}, @cm)
+ @course.storage_quota.should == 4
+ end
+ end
+
end
describe Course, "enrollments" do

0 comments on commit f879b3b

Please sign in to comment.