Class: CrudComponents::Admin::Gate
- Inherits:
-
Object
- Object
- CrudComponents::Admin::Gate
- Defined in:
- lib/crud_components/admin/gate.rb
Overview
Who may in at all, as one verdict the controller only has to carry out. It decides nothing beyond the door: what a visitor may see and do inside is the app's ordinary ability, asked per model and per action.
Constant Summary collapse
- ACTION =
:access- VERDICTS =
%i[open block unauthorized allowed forbidden].freeze
Instance Method Summary collapse
- #forbidden_message ⇒ Object
-
#initialize(config, ability) ⇒ Gate
constructor
A new instance of Gate.
- #unauthorized_message ⇒ Object
- #verdict ⇒ Object
Constructor Details
#initialize(config, ability) ⇒ Gate
Returns a new instance of Gate.
11 12 13 14 |
# File 'lib/crud_components/admin/gate.rb', line 11 def initialize(config, ability) @config = config @ability = ability end |
Instance Method Details
#forbidden_message ⇒ Object
33 |
# File 'lib/crud_components/admin/gate.rb', line 33 def = "not allowed to #{ACTION} the admin" |
#unauthorized_message ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/crud_components/admin/gate.rb', line 25 def "The admin asks `can?(#{ACTION.inspect}, #{subject.inspect})`, and nothing here answers `can?`. " \ 'Add CanCanCan, or configure a gate of your own: ' \ 'CrudComponents::Admin.configure { |c| c.auth_with { … } } — ' \ "or say `c.auth_with :none` on purpose (see docs/admin.md).\n" \ "In an ability: `can #{ACTION.inspect}, #{subject.inspect}`." end |
#verdict ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/crud_components/admin/gate.rb', line 16 def verdict return :open if @config.open_gate? return :block if @config.auth_block return :unauthorized if @ability.nil? return :allowed if @ability.can?(ACTION, subject) :forbidden end |