Skip to content

Commit

Permalink
role requirements are inheritable
Browse files Browse the repository at this point in the history
git-svn-id: http://rolerequirement.googlecode.com/svn/trunk@54 0128ec72-9f35-0410-83f6-31648bef6b25
  • Loading branch information
timcharper committed Aug 15, 2007
1 parent afa3572 commit 2c725d2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/role_requirement_system.rb
Expand Up @@ -4,6 +4,7 @@
# See RoleSecurityClassMethods for some methods it provides.
module RoleRequirement
def self.included(klass)
klass.send :class_inheritable_array, :role_requirements
klass.send :include, RoleSecurityInstanceMethods
klass.send :extend, RoleSecurityClassMethods
klass.send :helper_method, :url_options_authenticate?
Expand All @@ -12,7 +13,7 @@ def self.included(klass)
module RoleSecurityClassMethods

def reset_role_requirements!
@role_requirements=nil
self.role_requirements=nil
end

# Add this to the top of your controller to require a role in order to access it.
Expand Down Expand Up @@ -49,14 +50,14 @@ def require_role(roles, options = {})
end
end

@role_requirements||=[]
@role_requirements << {:roles => roles, :options => options }
self.role_requirements||=[]
self.role_requirements << {:roles => roles, :options => options }
end

# This is the core of RoleRequirement. Here is where it discerns if a user can access a controller or not./
def user_authorized_for?(user, params = {}, binding = self.binding)
return true unless Array===@role_requirements
@role_requirements.each{| role_requirement|
return true unless Array===self.role_requirements
self.role_requirements.each{| role_requirement|
roles = role_requirement[:roles]
options = role_requirement[:options]
# do the options match the params?
Expand Down

0 comments on commit 2c725d2

Please sign in to comment.