Module: Rbacan::Authorization
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rbacan/authorization.rb
Instance Method Summary collapse
-
#authorize!(permission, context: nil) ⇒ Object
Calls the unauthorized handler if current_user lacks the given permission.
-
#authorize_role!(role, context: nil) ⇒ Object
Calls the unauthorized handler if current_user lacks the given role.
Instance Method Details
#authorize!(permission, context: nil) ⇒ Object
Calls the unauthorized handler if current_user lacks the given permission.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rbacan/authorization.rb', line 9 def (, context: nil) allowed = if Rbacan.legacy_mode current_user&.can?(.to_s) else Rbacan.( user: current_user, permission: , context: context || ) end unless allowed (permission: .to_s) end end |
#authorize_role!(role, context: nil) ⇒ Object
Calls the unauthorized handler if current_user lacks the given role.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rbacan/authorization.rb', line 26 def (role, context: nil) allowed = if Rbacan.legacy_mode current_user&.has_role?(role.to_s) else Rbacan.( user: current_user, role: role, context: context || ) end unless allowed (role: role.to_s) end end |