Sha256: 70e87aa405dcc33a3313290bdb5f00b1c1ab0984379c4c045647ade7d5dce8d6

Contents?: true

Size: 997 Bytes

Versions: 20

Compression:

Stored size: 997 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.empty?
          end
          can :promote, Decidim::User do |user_to_promote|
            user_to_promote.managed? && Decidim::ImpersonationLog.active.empty?
          end
        end

        private

        def empty_available_authorizations?
          @context[:current_organization] && @context[:current_organization].available_authorizations.empty?
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
decidim-admin-0.6.7 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.6.7 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.6.6 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.6.6 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.6.5 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.6.5 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.6.4 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.6.4 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.6.3 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.6.3 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.6.2 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.6.2 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.6.1 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.6.1 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.6.0 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.6.0 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.5.1 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.5.1 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-admin-0.5.0 app/models/decidim/admin/abilities/user_manager_ability.rb
decidim-0.5.0 decidim-admin/app/models/decidim/admin/abilities/user_manager_ability.rb