Class: Ability

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
app/models/ability.rb

Overview

Thin dispatcher — selects the right focused ability class based on party type.

  • CRM controllers (CrmController hierarchy) override +current_ability+ to
    return +CrmAbility+ directly, so this class is never reached for employee
    sessions in the CRM.

  • WWW portal controllers (BasePortalController hierarchy) override
    +current_ability+ to return +CustomerPortalAbility+ directly.

  • All other controllers (API, webhooks, admin namespace, mailer previews, etc.)
    that do not override +current_ability+ fall back to this class, which merges
    the appropriate focused ability so the rules are still correct.

See CrmAbility and CustomerPortalAbility for the actual rule definitions.

Instance Method Summary collapse

Constructor Details

#initialize(party) ⇒ Ability



22
23
24
25
26
27
28
29
30
# File 'app/models/ability.rb', line 22

def initialize(party)
  case party
  when Employee
    merge CrmAbility.new(party)
  when Customer, Contact
    merge CustomerPortalAbility.new(party)
  end
  # nil party or unknown type → no permissions (empty ability)
end