Sha256: f7813627bcc59b8d7a883a33e3f794f4e397a53d62a118a7ee30d53fbb0b25ae

Contents?: true

Size: 950 Bytes

Versions: 2

Compression:

Stored size: 950 Bytes

Contents

module ForemanPuppet
  module Extensions
    module User
      extend ActiveSupport::Concern

      def visible_environments
        authorized_scope = Environment.unscoped.authorized(:view_environments)
        authorized_scope = authorized_scope
                           .joins(:taxable_taxonomies)
                           .where('taxable_taxonomies.taxonomy_id' => taxonomy_ids[:organizations] + taxonomy_ids[:locations])
        result = authorized_scope.distinct.pluck(:name)
        if User.current.admin?
          # Admin users can also see Environments that do not have any organization or location, even when
          # organizations and locations are enabled.
          untaxed_environments = Environment.unscoped.where.not(id: TaxableTaxonomy.where(taxable_type: 'ForemanPuppet::Environment').distinct.select(:taxable_id)).pluck(:name)
          result += untaxed_environments
        end
        result
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_puppet-0.0.2 app/models/concerns/foreman_puppet/extensions/user.rb
foreman_puppet-0.0.1 app/models/concerns/foreman_puppet/extensions/user.rb