Sha256: 0484b034094f5ef66fdbe2bf8db3f0c61d6f438e437303dc063a00baff8fb0e7

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  # Defines the abilities for a User. Intended to be used with `cancancan`.
  class Ability
    include CanCan::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.
    # context - a Hash with some context related to the current request.
    def initialize(user, context = {})
      Decidim.abilities.each do |ability|
        merge ability.constantize.new(user, context)
      end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-core-0.4.2 app/models/decidim/ability.rb
decidim-core-0.4.1 app/models/decidim/ability.rb
decidim-core-0.4.3 app/models/decidim/ability.rb
decidim-core-0.4.0 app/models/decidim/ability.rb
decidim-core-0.3.2 app/models/decidim/ability.rb
decidim-core-0.3.1 app/models/decidim/ability.rb
decidim-core-0.3.0 app/models/decidim/ability.rb
decidim-core-0.2.0 app/models/decidim/ability.rb