Class: Decidim::Ability

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

Overview

Defines the abilities for a User. Intended to be used with ‘cancancan`.

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Ability

Initializes the ability class for the given user. Automatically merges injected abilities fmor the configuration. In order to inject more abilities, add this code in the ‘engine.rb` file of your own engine, for example, inside an initializer:

Decidim.configure do |config|
  config.abilities << Decidim::MyEngine::Abilities::MyAbility
end

Note that, in development, this will force you to restart the server every time you change things in your ability classes.

user - the User that needs its abilities checked.



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

def initialize(user)
  Decidim.abilities.each do |ability|
    merge ability.new(user)
  end

  can :manage, Authorization do |authorization|
    authorization.user == user
  end

  can :read, :user_account if user
end