Sha256: 59dffebf72291fde1145fc864e83f7d87e8818e41e316d0f3d3cf8029393ce56

Contents?: true

Size: 1.33 KB

Versions: 23

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Decidim
  module Abilities
    # Defines the abilities for a User. Intended to be used with `cancancan`.
    class BaseAbility
      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

        can :manage, Follow do |follow|
          follow.user == user
        end

        can :manage, Notification do |notification|
          notification.user == user
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
decidim-core-0.7.4 app/models/decidim/abilities/base_ability.rb
decidim-core-0.7.3 app/models/decidim/abilities/base_ability.rb
decidim-core-0.7.2 app/models/decidim/abilities/base_ability.rb
decidim-core-0.7.1 app/models/decidim/abilities/base_ability.rb
decidim-core-0.7.0 app/models/decidim/abilities/base_ability.rb
decidim-core-0.6.8 app/models/decidim/abilities/base_ability.rb
decidim-0.6.8 decidim-core/app/models/decidim/abilities/base_ability.rb
decidim-core-0.6.7 app/models/decidim/abilities/base_ability.rb
decidim-0.6.7 decidim-core/app/models/decidim/abilities/base_ability.rb
decidim-core-0.6.6 app/models/decidim/abilities/base_ability.rb
decidim-0.6.6 decidim-core/app/models/decidim/abilities/base_ability.rb
decidim-core-0.6.5 app/models/decidim/abilities/base_ability.rb
decidim-0.6.5 decidim-core/app/models/decidim/abilities/base_ability.rb
decidim-core-0.6.4 app/models/decidim/abilities/base_ability.rb
decidim-0.6.4 decidim-core/app/models/decidim/abilities/base_ability.rb
decidim-core-0.6.3 app/models/decidim/abilities/base_ability.rb
decidim-0.6.3 decidim-core/app/models/decidim/abilities/base_ability.rb
decidim-core-0.6.2 app/models/decidim/abilities/base_ability.rb
decidim-0.6.2 decidim-core/app/models/decidim/abilities/base_ability.rb
decidim-core-0.6.1 app/models/decidim/abilities/base_ability.rb