-
Notifications
You must be signed in to change notification settings - Fork 399
Open
Description
From the Usage page, it should be possible to pass has_any_role? both the name of a global role, or a resource-specific role.
user.has_any_role? :admin, { :name => :moderator, :resource => Forum.first }, { :name => :visitor, :resource => Forum }However, for a new record, when the {name: ..., resource: ...} form of a role is passed, has_any_role? passes the hash directly to has_role?.
def has_any_role?(*args)
if new_record?
args.any? { |r| self.has_role?(r) }
else
# ...
endhas_role? is none-too-happy about this, expecting to get between one and two arguments.
def has_role?(role_name, resource = nil)
# ...
endFor comparison, has_all_roles? gets this right.
def has_all_roles?(*args)
args.each do |arg|
if arg.is_a? Hash
return false if !self.has_role?(arg[:name], arg[:resource])
elsif arg.is_a?(String) || arg.is_a?(Symbol)
return false if !self.has_role?(arg)
else
# ...
endI've had this bug bite me locally and can confirm it is no fun.
Happy to submit a PR, but figured I'd get a report first.
Metadata
Metadata
Assignees
Labels
No labels