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-0.6.8 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.7 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.6.7 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.6 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.6.6 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.5 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.6.5 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.4 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.6.4 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.3 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.6.3 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.2 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.6.2 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.1 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.6.1 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.6.0 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.6.0 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.5.1 app/models/decidim/abilities/user_manager_ability.rb
decidim-0.5.1 decidim-core/app/models/decidim/abilities/user_manager_ability.rb
decidim-core-0.5.0 app/models/decidim/abilities/user_manager_ability.rb