lib/authz/controllers/scoping_manager.rb in authz-0.0.1.alpha4 vs lib/authz/controllers/scoping_manager.rb in authz-0.0.1.alpha5
- old
+ new
@@ -13,11 +13,11 @@
def self.has_access_to_instance?(role, instance_to_check, authz_user)
scoped_class = instance_to_check.class
applicable_scopables = Authz::Scopables::Base.get_applicable_scopables! scoped_class
applicable_scopables.each do |as|
- kw = role.scoping_rules.find_by!(scopable: as.to_s).keyword
+ kw = role.cached_granted_keyword_for(as)
return false unless as.within_scope_of_keyword?(instance_to_check,
kw,
authz_user)
end
@@ -61,13 +61,14 @@
# @param authz_user: the requesting user (injected dependency)
def self.apply_role_scopes(role, collection_or_class, authz_user)
applicable_scopables = Authz::Scopables::Base.get_applicable_scopables! collection_or_class
scoped = collection_or_class.all
+
applicable_scopables.each do |as|
# as = ScopableByCity
- kw = role.scoping_rules.find_by!(scopable: as.to_s).keyword
+ kw = role.cached_granted_keyword_for(as)
# kw = 'New York'
scoped = scoped.send(as.apply_scopable_method_name, kw, authz_user)
# scoped.apply_scopable_by_city('New York', User#123)
end