make permission_cache_key_for shard aware

fixes: CNVS-13917

Moves the initializer from active record base to an alias method chain
on AdheresToPolicy::Instance methods.  The way its including the
instance methods did not allow it to override the
permission_cache_key_for method.

Test Case:

  - Flush cache
  - Open a Course
  - Look at the cache keys and all the ids should be global ids

Change-Id: Iac6a5ed95a800c27bd53fcb757cabd11976aef21
Reviewed-on: https://gerrit.instructure.com/37226
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Nick Cloward <ncloward@instructure.com>
This commit is contained in:
Nick Cloward 2014-07-02 14:58:53 -06:00
parent 3c11a4cb1e
commit f96ef2c3d1
3 changed files with 14 additions and 7 deletions

View File

@ -145,11 +145,6 @@ class ActiveRecord::Base
@global_asset_string ||= "#{self.class.reflection_type_name}_#{global_id}"
end
# Override the adheres_to_policy permission_cache_key for to make it shard aware.
def permission_cache_key_for(user, session, right)
Shard.default.activate { super }
end
# little helper to keep checks concise and avoid a db lookup
def has_asset?(asset, field = :context)
asset.id == send("#{field}_id") && asset.class.base_ar_class.name == send("#{field}_type")

View File

@ -1,2 +1,15 @@
require 'adheres_to_policy'
ActiveRecord::Base.send :extend, AdheresToPolicy::ClassMethods
ActiveRecord::Base.send :extend, AdheresToPolicy::ClassMethods
module AdheresToPolicy::InstanceMethods
# Override the adheres_to_policy permission_cache_key for to make it shard aware.
def permission_cache_key_for_with_sharding(user, session, right)
Shard.default.activate do
permission_cache_key_for_without_sharding(user, session, right)
end
end
alias_method_chain :permission_cache_key_for, :sharding
end

View File

@ -325,7 +325,6 @@ module AdheresToPolicy
value = some_array.collect { |element| ActiveSupport::Cache.expand_cache_key(element) }.to_param
some_array.instance_variable_set("@cache_key", value) unless some_array.frozen?
value
some_array.collect { |element| ActiveSupport::Cache.expand_cache_key(element) }.to_param
end