diff --git a/config/initializers/active_record.rb b/config/initializers/active_record.rb index 5668a518d58..214062253ab 100644 --- a/config/initializers/active_record.rb +++ b/config/initializers/active_record.rb @@ -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") diff --git a/config/initializers/adheres_to_policy.rb b/config/initializers/adheres_to_policy.rb index 6db1b1f4277..6e53f8acafd 100644 --- a/config/initializers/adheres_to_policy.rb +++ b/config/initializers/adheres_to_policy.rb @@ -1,2 +1,15 @@ require 'adheres_to_policy' -ActiveRecord::Base.send :extend, AdheresToPolicy::ClassMethods \ No newline at end of file + +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 diff --git a/gems/adheres_to_policy/lib/adheres_to_policy/instance_methods.rb b/gems/adheres_to_policy/lib/adheres_to_policy/instance_methods.rb index fc42b35e49a..6192bbac278 100644 --- a/gems/adheres_to_policy/lib/adheres_to_policy/instance_methods.rb +++ b/gems/adheres_to_policy/lib/adheres_to_policy/instance_methods.rb @@ -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