diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index a114bba31..679ffc909 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -302,7 +302,7 @@ def extract_subjects(subject) def alternative_subjects(subject) subject = subject.class unless subject.is_a?(Module) - if subject.respond_to?(:subclasses) && subject < ActiveRecord::Base + if subject.respond_to?(:subclasses) && defined?(ActiveRecord::Base) && subject < ActiveRecord::Base [:all, *(subject.ancestors + subject.subclasses), subject.class.to_s] else [:all, *subject.ancestors, subject.class.to_s] diff --git a/lib/cancan/model_adapters/sti_normalizer.rb b/lib/cancan/model_adapters/sti_normalizer.rb index a2ac739f8..85b6c0145 100644 --- a/lib/cancan/model_adapters/sti_normalizer.rb +++ b/lib/cancan/model_adapters/sti_normalizer.rb @@ -6,12 +6,11 @@ class StiNormalizer class << self def normalize(rules) rules_cache = [] - rules.delete_if.with_index do |rule, _index| - subjects = rule.subjects.select do |subject| - next if subject == :all || subject.descends_from_active_record? + return unless defined?(ActiveRecord::Base) - rules_cache.push(build_rule_for_subclass(rule, subject)) - true + rules.delete_if do |rule| + subjects = rule.subjects.select do |subject| + update_rule(subject, rule, rules_cache) end subjects.length == rule.subjects.length end @@ -20,6 +19,15 @@ def normalize(rules) private + def update_rule(subject, rule, rules_cache) + return false unless subject.respond_to?(:descends_from_active_record?) + return false if subject == :all || subject.descends_from_active_record? + return false unless subject < ActiveRecord::Base + + rules_cache.push(build_rule_for_subclass(rule, subject)) + true + end + # create a new rule for the subclasses that links on the inheritance_column def build_rule_for_subclass(rule, subject) CanCan::Rule.new(rule.base_behavior, rule.actions, subject.superclass, diff --git a/logo/modern_treasury.svg b/logo/modern_treasury.svg index c0ac10d63..8a15c495a 100644 --- a/logo/modern_treasury.svg +++ b/logo/modern_treasury.svg @@ -1,13 +1,14 @@ - -