use dummy root account for user and site admin content migrations
refs #LS-1361 Change-Id: Ie9ab343027b636cb28169385341aea4829938c7d Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/246934 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: James Williams <jamesw@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
df360b2a15
commit
f781e96cff
|
@ -2014,4 +2014,8 @@ class Account < ActiveRecord::Base
|
|||
|
||||
relation_delegate_class(ActiveRecord::Relation).prepend(DomainRootAccountCache)
|
||||
relation_delegate_class(ActiveRecord::AssociationRelation).prepend(DomainRootAccountCache)
|
||||
|
||||
def self.ensure_dummy_root_account
|
||||
Account.find_or_create_by!(id: 0) if Rails.env.test?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,7 +36,6 @@ class ContentMigration < ActiveRecord::Base
|
|||
after_save :handle_import_in_progress_notice
|
||||
after_save :check_for_blocked_migration
|
||||
before_create :set_root_account_id
|
||||
attr_accessor :skip_root_account_assignment
|
||||
|
||||
DATE_FORMAT = "%m/%d/%Y"
|
||||
|
||||
|
@ -985,13 +984,15 @@ class ContentMigration < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def set_root_account_id
|
||||
return if skip_root_account_assignment
|
||||
case self.context
|
||||
when Course, Group
|
||||
self.root_account_id = self.context.root_account_id
|
||||
self.root_account_id ||= self.context.root_account_id
|
||||
when Account
|
||||
self.root_account_id = self.context.resolved_root_account_id
|
||||
self.root_account_id ||= self.context.resolved_root_account_id
|
||||
when User
|
||||
self.root_account_id ||= 0
|
||||
end
|
||||
Account.ensure_dummy_root_account if root_account_id == 0
|
||||
end
|
||||
|
||||
def notification_link_anchor
|
||||
|
|
|
@ -146,7 +146,7 @@ module AcademicBenchmark
|
|||
cm.migration_settings[:migration_options] = options
|
||||
cm.strand = "academic_benchmark"
|
||||
cm.user = user
|
||||
cm.skip_root_account_assignment = true
|
||||
cm.root_account_id = 0
|
||||
cm.save!
|
||||
[cm, cm.export_content]
|
||||
end
|
||||
|
|
|
@ -248,7 +248,7 @@ describe AcademicBenchmark::Converter do
|
|||
document: 'document',
|
||||
user: @user
|
||||
)[0]
|
||||
expect(cm.root_account_id).to be_nil
|
||||
expect(cm.root_account_id).to eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue