Module: UserHelper
- Defined in:
- lib/generators/templates/helpers/user_helper.rb
Overview
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.
29 30 31 32 |
# File 'lib/generators/templates/helpers/user_helper.rb', line 29 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.
9 10 11 12 |
# File 'lib/generators/templates/helpers/user_helper.rb', line 9 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.
18 19 20 21 |
# File 'lib/generators/templates/helpers/user_helper.rb', line 18 def has_roles?(*args) throw Exception.new("Must supply at least one role.") if args.empty? roles.where(name: args).count == args.count end |