2020-10-27 00:50:13 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 03:59:16 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2015 - present Instructure, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
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
|
2020-09-10 23:01:25 +08:00
|
|
|
md5 = Rails.cache.fetch_with_batched_keys("effective_brand_config_md5", batch_object: self, batched_keys: [:account_chain, :brand_config]) do
|
|
|
|
brand_config_chain(include_self: true).select(&:branding_allowed?).find(&:brand_config_md5)&.brand_config_md5
|
|
|
|
end
|
2020-10-30 02:49:19 +08:00
|
|
|
# ensure the BrandConfig query hits the correct shard
|
|
|
|
shard.activate do
|
|
|
|
md5 && BrandConfig.find_cached_by_md5(md5)
|
|
|
|
end
|
2015-08-21 22:29:35 +08:00
|
|
|
end
|
|
|
|
|
2015-08-15 02:42:55 +08:00
|
|
|
def first_parent_brand_config
|
2020-09-10 23:01:25 +08:00
|
|
|
brand_config_chain(include_self: false).find(&:brand_config_md5).try(:brand_config)
|
2015-08-15 02:42:55 +08:00
|
|
|
end
|
|
|
|
|
2021-07-30 01:27:38 +08:00
|
|
|
private
|
|
|
|
|
2016-05-28 05:22:25 +08:00
|
|
|
def brand_config_chain(include_self:)
|
2021-07-30 01:27:38 +08:00
|
|
|
chain = self.account_chain(include_site_admin: true).dup
|
2016-05-28 05:22:25 +08:00
|
|
|
chain.shift unless include_self
|
2021-07-30 01:27:38 +08:00
|
|
|
chain.select! { |a| a.shard == self.shard }
|
2016-08-09 23:28:06 +08:00
|
|
|
chain
|
2016-05-28 05:22:25 +08:00
|
|
|
end
|
2015-08-15 02:42:55 +08:00
|
|
|
end
|