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
|
2022-03-11 05:25:35 +08:00
|
|
|
shard_id, md5 = Rails.cache.fetch_with_batched_keys("effective_brand_config_ids", batch_object: self, batched_keys: [:account_chain, :brand_config]) do
|
|
|
|
branded_account = brand_config_chain(include_self: true).select(&:branding_allowed?).find(&:brand_config_md5)
|
|
|
|
[branded_account&.shard&.id, branded_account&.brand_config_md5]
|
2020-10-30 02:49:19 +08:00
|
|
|
end
|
2022-03-11 05:25:35 +08:00
|
|
|
return nil unless md5
|
|
|
|
|
|
|
|
BrandConfig.find_cached_by_md5(shard_id, md5)
|
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:)
|
2022-03-25 02:42:54 +08:00
|
|
|
# It would be surprising to legacy consortia to have theme settings inherit
|
|
|
|
# even though that would be the more correct behavior given the general
|
|
|
|
# conecept of account chains, so explicitly tack site admin onto the chain
|
|
|
|
# so we always inherit from siteadmin even if we don't want consortia parents
|
|
|
|
chain = account_chain(include_federated_parent: !root_account.primary_settings_root_account?).dup
|
|
|
|
chain << Account.site_admin unless chain.include?(Account.site_admin)
|
2016-05-28 05:22:25 +08:00
|
|
|
chain.shift unless include_self
|
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
|