Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixing 2d caching

  • Loading branch information...
commit 41923f5a328a70389395441ee5e3a76e2282410c 1 parent b79bea2
@pschrammel authored
View
7 app/models/active_acl/acl.rb
@@ -1,6 +1,13 @@
# This model is the "glue" :-). Every permission assignment uses an Acl
# model object, assigns objects, groups and privileges and setting
# 'allow' to "true" or "false" to grant or deny access.
+
+# These methods are added by the acts_as_access_object/group:
+# requesters
+# targets
+# requester_groups
+# target_groups
+
module ActiveAcl
class Acl < ActiveRecord::Base
set_table_name ActiveAcl::OPTIONS[:acls_table]
View
42 lib/active_acl/grant.rb
@@ -3,30 +3,44 @@ module Acts
module Grant
# grant_permission!(Blog::DELETE,
# :on => blog,
- # :section_name => 'blogging'
- # :acl_name => 'blogging_of_admins'
+ # :section => 'blogging' or a Hash or an ActiveAcl::AclSection
+ # :acl => 'blogging_of_admins' or a hash or an ActiveAvl::Acl
+ # :target_as_object => true/false target is treated as access_object
def grant_permission!(privilege,options={})
- section_name = options[:section_name] || 'generic'
+ section = options[:section] || 'generic'
target = options[:on]
- iname = options[:acl_name] || "#{privilege.active_acl_description}"
- acl=nil
+ acl = options[:acl] || "#{privilege.active_acl_description}"
ActiveAcl::Acl.transaction do
- section = ActiveAcl::AclSection.find_or_create_by_iname(section_name)
- section.save! if section.new_record?
- acl = ActiveAcl::Acl.create :section => section,:iname => iname
- acl.save!
+ unless acl.kind_of?(ActiveAcl::Acl)
+ case section
+ when String
+ section = ActiveAcl::AclSection.find_or_create_by_iname(section)
+ when Hash
+ section = ActiveAcl::AclSection.create(section)
+ #else section should be an ActiveAcl::AclSection
+ end
+ section.save! if section.new_record?
+ end
+
+ case acl
+ when String
+ acl=ActiveAcl::Acl.find_or_create_by_iname(acl)
+ when Hash
+ acl=ActiveAcl::Acl.create(acl.merge({:section => section}))
+ end
+ acl.save! if acl.new_record?
acl.privileges << privilege
if ActiveAcl.is_access_group?(self.class)
- acl.requester_groups << self
+ acl.requester_groups << self unless acl.requester_groups.include?(self)
else
- acl.requesters << self
+ acl.requesters << self unless acl.requesters.include?(self)
end
if target
- if ActiveAcl.is_access_group?(target.class)
- acl.target_groups << target
+ if ActiveAcl.is_access_group?(target.class) && !options[:target_as_object]
+ acl.target_groups << target unless acl.target_groups.include?(target)
else
- acl.targets << target
+ acl.targets << target unless acl.targets.include?(target)
end
end
active_acl_clear_cache! if ActiveAcl.is_access_object?(self.class)
View
9 lib/active_acl/handler/object_handler.rb
@@ -18,6 +18,9 @@ def initialize(klass,options={})
@habtm = options[:habtm] || (options[:grouped_by].to_s.demodulize.singularize != options[:grouped_by].to_s.demodulize)
end
+ logger=Rails.logger
+ logger.debug "ActiveAcl: registered ObjectHandler for #{klass}"
+ logger.debug "grouped: #{self.grouped?}, habtm: #{habtm?}"
#set the SQL fragments
prepare_requester_sql
prepare_target_sql
@@ -147,13 +150,13 @@ def set_cached(requester,privilege,target,results)
results.each do |row|
if row['privilege_id'] != last_privilege_value
last_privilege_value = row['privilege_id']
- q_id=query_id(requester,privilege,target)
- #TODO: put the into the db handler
+ q_id=query_id(requester,last_privilege_value,nil)
+ #TODO: put the true comparison into the db handler
v=((row['allow'] == '1') or (row['allow'] == 't'))
instance_cache[q_id] = v
end
end
- requester.active_acl_cached_2d! #mark the cache as cached (at least 2d)
+ requester.active_acl_cached_2d! #mark the cache as filled (at least 2d)
# the result should be in the cache now or we return false
value=instance_cache[this_query_id] || false
else #3d request?
Please sign in to comment.
Something went wrong with that request. Please try again.