Module: Rarbac::UserHelper
- Defined in:
- app/helpers/rarbac/user_helper.rb
Overview
A collection of useful functions to be used by the user model.
include Rarbac::UserHelper
That’s it! Now you have access to some awesome RBAC helper functions.
Instance Method Summary collapse
-
#has_permission?(action) ⇒ true|false
Determines if the user has permission to a given action.
-
#has_role?(*args) ⇒ true|false
Determines if the user has one or more of the given roles linked to it.
-
#has_roles?(*args) ⇒ true|false
Determines if the user has all of the given roles linked to it.
Instance Method Details
#has_permission?(action) ⇒ true|false
Determines if the user has permission to a given action. If the action does not exist at all, it is assumed the action is publicly available.
33 34 35 36 |
# File 'app/helpers/rarbac/user_helper.rb', line 33 def (action) return true if Action.where(name: action).count == 0 actions.where(name: action).count > 0 end |
#has_role?(*args) ⇒ true|false
Determines if the user has one or more of the given roles linked to it.
13 14 15 16 |
# File 'app/helpers/rarbac/user_helper.rb', line 13 def has_role?(*args) throw Exception.new("Must supply at least one role.") if args.empty? roles.where(name: args).count > 0 end |
#has_roles?(*args) ⇒ true|false
Determines if the user has all of the given roles linked to it.
22 23 24 25 |
# File 'app/helpers/rarbac/user_helper.rb', line 22 def has_roles?(*args) throw Exception.new("Must supply at least one role.") if args.empty? roles.where(name: args).count == args.count end |