Class: RuboCop::Cop::Guardrails::NoInlineAuthorization
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Guardrails::NoInlineAuthorization
- Includes:
- VisibilityHelpers
- Defined in:
- lib/rubocop/cop/guardrails/no_inline_authorization.rb
Overview
Flags inline authorization checks in controller actions.
Authorization responses like ‘head :forbidden`, `head :unauthorized`, or `render status: :forbidden` should live in a `before_action` callback, not inline in an action method. This keeps actions focused on the happy path.
Constant Summary collapse
- MSG =
'Extract authorization to a `before_action` callback.'- RESTRICT_ON_SEND =
%i[head render].freeze
- AUTHORIZATION_STATUSES =
%i[forbidden unauthorized].to_set.freeze
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
48 49 50 |
# File 'lib/rubocop/cop/guardrails/no_inline_authorization.rb', line 48 def on_send(node) add_offense(node) if (node) && in_public_method?(node) end |