return a frozen account chain
so that we can return the same one every time if called multiple times for the same context Change-Id: I2c5825ab115c50d1332d05d1e3cecbe45cbe7ea1 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/270297 Reviewed-by: Jacob Burroughs <jburroughs@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
d2d5f7d36e
commit
db153f2beb
|
@ -365,9 +365,9 @@ class OutcomeGroupsApiController < ApplicationController
|
|||
|
||||
account_chain =
|
||||
if @context.is_a?(Account)
|
||||
@context.account_chain - [@context]
|
||||
@context.account_chain[1..]
|
||||
else
|
||||
@context.account.account_chain
|
||||
@context.account.account_chain.dup
|
||||
end
|
||||
account_chain.map! {|a| {
|
||||
:id => a.root_outcome_group.id,
|
||||
|
|
|
@ -999,10 +999,11 @@ class Account < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def account_chain(include_site_admin: false)
|
||||
@account_chain ||= Account.account_chain(self)
|
||||
result = @account_chain.dup
|
||||
Account.add_site_admin_to_chain!(result) if include_site_admin
|
||||
result
|
||||
@account_chain ||= Account.account_chain(self).freeze
|
||||
if include_site_admin
|
||||
return @account_chain_with_site_admin ||= Account.add_site_admin_to_chain!(@account_chain.dup).freeze
|
||||
end
|
||||
@account_chain
|
||||
end
|
||||
|
||||
def account_chain_ids
|
||||
|
@ -1365,7 +1366,7 @@ class Account < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def reload(*)
|
||||
@account_chain = nil
|
||||
@account_chain = @account_chain_with_site_admin = nil
|
||||
super
|
||||
end
|
||||
|
||||
|
|
|
@ -1430,6 +1430,11 @@ class Course < ActiveRecord::Base
|
|||
workflow_state
|
||||
end
|
||||
|
||||
def reload(*)
|
||||
@account_chain = @account_chain_with_site_admin = nil
|
||||
super
|
||||
end
|
||||
|
||||
alias destroy_permanently! destroy
|
||||
def destroy
|
||||
return false if template?
|
||||
|
@ -1850,10 +1855,11 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def account_chain(include_site_admin: false)
|
||||
@account_chain ||= Account.account_chain(account_id)
|
||||
result = @account_chain.dup
|
||||
Account.add_site_admin_to_chain!(result) if include_site_admin
|
||||
result
|
||||
@account_chain ||= Account.account_chain(account_id).freeze
|
||||
if include_site_admin
|
||||
return @account_chain_with_site_admin ||= Account.add_site_admin_to_chain!(@account_chain.dup).freeze
|
||||
end
|
||||
@account_chain
|
||||
end
|
||||
|
||||
def account_chain_ids
|
||||
|
|
|
@ -83,9 +83,10 @@ module Lti
|
|||
resource_type_code: resource_type_code,
|
||||
context: context)
|
||||
resource_handler = nil
|
||||
search_contexts = context.account_chain.unshift(context)
|
||||
search_contexts = context.account_chain.dup.unshift(context)
|
||||
search_contexts.each do |search_context|
|
||||
break if resource_handler.present?
|
||||
|
||||
resource_handler = possible_handlers.find { |rh| rh.tool_proxy.context == search_context }
|
||||
end
|
||||
resource_handler&.find_message_by_type(message_type)
|
||||
|
|
|
@ -1634,7 +1634,6 @@ class RoleOverride < ActiveRecord::Base
|
|||
|
||||
preloaded_overrides ||= preload_overrides(context, [role], role_context)
|
||||
|
||||
accounts.reverse!
|
||||
overrides = {}
|
||||
|
||||
dummies = RequestCache.cache('role_override_dummies') do
|
||||
|
@ -1647,7 +1646,7 @@ class RoleOverride < ActiveRecord::Base
|
|||
preloaded_overrides.each do |(permission, overrides_by_account)|
|
||||
next if only_permission && permission != only_permission
|
||||
|
||||
overrides[permission] = accounts.map do |account|
|
||||
overrides[permission] = accounts.reverse_each.map do |account|
|
||||
overrides_by_account[account.global_id].find { |ro| ro.role_id == role.id } || dummies[account.id]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,13 +36,13 @@ module BrandConfigHelpers
|
|||
brand_config_chain(include_self: false).find(&:brand_config_md5).try(:brand_config)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def brand_config_chain(include_self:)
|
||||
chain = self.account_chain(include_site_admin: true)
|
||||
chain = self.account_chain(include_site_admin: true).dup
|
||||
chain.shift unless include_self
|
||||
chain.select!{ |a| a.shard == self.shard }
|
||||
chain.select! { |a| a.shard == self.shard }
|
||||
ActiveRecord::Associations::Preloader.new.preload(chain, :root_account)
|
||||
chain
|
||||
end
|
||||
private :brand_config_chain
|
||||
|
||||
end
|
||||
|
|
|
@ -110,7 +110,7 @@ module FeatureFlags
|
|||
RequestCache.cache('feature_flag_account_ids', self) do
|
||||
shard.activate do
|
||||
cache.fetch(['feature_flag_account_ids', self].cache_key) do
|
||||
chain = account_chain(include_site_admin: true)
|
||||
chain = account_chain(include_site_admin: true).dup
|
||||
chain.shift if is_a?(Account)
|
||||
chain.reverse.map(&:global_id)
|
||||
end
|
||||
|
|
|
@ -2099,6 +2099,7 @@ describe Account do
|
|||
au = AccountUser.create!(:account => other_account, :user => @user)
|
||||
expect(cached_account_users).to eq []
|
||||
@account.update_attribute(:parent_account, other_account)
|
||||
@account.reload
|
||||
expect(cached_account_users).to eq [au]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue