Sha256: b16c75ce996395beb7c47b871eff779a0afc8078d23d5a6929366a162c1d121b

Contents?: true

Size: 781 Bytes

Versions: 41

Compression:

Stored size: 781 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Abilities
    # Defines the abilities for an user with role 'user_manager'.
    # Intended to be used with `cancancan`.
    class UserManagerAbility
      include CanCan::Ability

      attr_reader :user

      def initialize(user, context)
        @user = user
        @context = context

        define_abilities if not_admin? && user_manager?
      end

      def define_abilities
        can :read, :admin_dashboard
        can :impersonate, :managed_users
      end

      # Whether the user is an admin or not.
      def not_admin?
        @user && !@user.admin?
      end

      # Whether the user has the user_manager role or not.
      def user_manager?
        @user.role? "user_manager"
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
decidim-core-0.11.2 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.11.1 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.11.0.pre1 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.10.1 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.10.0 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.9.3 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.9.2 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.9.1 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.9.0 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.8.4 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.8.3 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.8.2 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.8.1 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.8.0 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.7.4 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.7.3 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.7.2 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.7.1 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.7.0 app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.8 app/models/decidim/abilities/user_manager_ability.rb