Skip to content

Commit

Permalink
added has_any_role and fixed has_roles
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Jan 5, 2011
1 parent bfbce43 commit 355be48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.textile
Expand Up @@ -103,6 +103,8 @@ Embedded Role model (Document stores only):


Currently the embedded strategies have only been implemented for Mongoid. Currently the embedded strategies have only been implemented for Mongoid.


See "Roles strategy configuration":https://github.com/kristianmandrup/roles_generic/wiki/Roles-strategy-configuration for more info

h2. Role API h2. Role API


The full Roles API is described in these Wiki pages: The full Roles API is described in these Wiki pages:
Expand Down
9 changes: 7 additions & 2 deletions lib/roles_generic/generic/user/implementation.rb
Expand Up @@ -42,9 +42,14 @@ def exchange_role role, options = {}
exchange_roles role, options exchange_roles role, options
end end


# check if a given role has been assigned # check if all of the roles listed have been assigned to that user
# if a list of roles: check if ALL of the given roles have been assigned
def has_roles?(*roles_names) def has_roles?(*roles_names)
compare_roles = extract_roles(roles_names.flat_uniq)
(compare_roles - roles_list).empty?
end

# check if any of the roles listed have been assigned to that user
def has_any_role?(*roles_names)
compare_roles = extract_roles(roles_names.flat_uniq) compare_roles = extract_roles(roles_names.flat_uniq)
(roles_list & compare_roles).not.empty? (roles_list & compare_roles).not.empty?
end end
Expand Down

0 comments on commit 355be48

Please sign in to comment.