2015-08-15 02:42:55 +08:00
|
|
|
module BrandConfigHelpers
|
2015-08-21 22:29:35 +08:00
|
|
|
def branding_allowed?
|
2015-12-05 00:57:07 +08:00
|
|
|
root_account? || root_account.sub_account_includes?
|
|
|
|
end
|
|
|
|
|
|
|
|
def effective_brand_config
|
2016-05-28 05:22:25 +08:00
|
|
|
first_config_in_chain(
|
|
|
|
brand_config_chain(include_self: true).select(&:branding_allowed?)
|
|
|
|
)
|
2015-08-21 22:29:35 +08:00
|
|
|
end
|
|
|
|
|
2015-08-15 02:42:55 +08:00
|
|
|
def first_parent_brand_config
|
2016-05-28 05:22:25 +08:00
|
|
|
first_config_in_chain(brand_config_chain(include_self: false))
|
2015-08-15 02:42:55 +08:00
|
|
|
end
|
|
|
|
|
2016-05-28 05:22:25 +08:00
|
|
|
def brand_config_chain(include_self:)
|
|
|
|
chain = self.account_chain(include_site_admin: true)
|
|
|
|
chain.shift unless include_self
|
2016-08-09 23:28:06 +08:00
|
|
|
chain.select!{ |a| a.shard == self.shard }
|
|
|
|
ActiveRecord::Associations::Preloader.new.preload(chain, :root_account)
|
|
|
|
chain
|
2016-05-28 05:22:25 +08:00
|
|
|
end
|
|
|
|
private :brand_config_chain
|
|
|
|
|
|
|
|
def first_config_in_chain(chain)
|
|
|
|
chain.find(&:brand_config_md5).try(:brand_config)
|
|
|
|
end
|
|
|
|
private :first_config_in_chain
|
2015-08-15 02:42:55 +08:00
|
|
|
end
|