Module: Rbacan::ViewHelpers

Defined in:
lib/rbacan/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#authorized?(permission, context: nil, &block) ⇒ Boolean

Renders the block only when the host authorization adapter permits it.

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rbacan/view_helpers.rb', line 4

def authorized?(permission, context: nil, &block)
  allowed = if Rbacan.legacy_mode
              current_user&.can?(permission.to_s)
            else
              Rbacan.authorized?(
                user: current_user,
                permission: permission,
                context: context || rbacan_authorization_context
              )
            end
  return unless allowed

  capture(&block) if block_given?
end