Sha256: e0f3255f35566d9b03817a172609806d5f3c739a1ee1a06a49050f358f670204

Contents?: true

Size: 989 Bytes

Versions: 18

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    module Abilities
      # Defines the abilities for a user with role 'user_manager' in the admin section.
      # Intended to be used with `cancancan`.
      class UserManagerAbility < Decidim::Abilities::UserManagerAbility
        def define_abilities
          super

          can :manage, :managed_users

          cannot [:new, :create], :managed_users if empty_available_authorizations?

          can :impersonate, Decidim::User do |user_to_impersonate|
            user_to_impersonate.managed? && Decidim::ImpersonationLog.active.where(admin: user).empty?
          end

          can :promote, Decidim::User do |user_to_promote|
            user_to_promote.managed? && Decidim::ImpersonationLog.active.where(admin: user).empty?
          end
        end

        private

        def empty_available_authorizations?
          user.organization.available_authorizations.empty?
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

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