Module: ForemanPuppet::Extensions::User

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/foreman_puppet/extensions/user.rb

Instance Method Summary collapse

Instance Method Details

#visible_environmentsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/concerns/foreman_puppet/extensions/user.rb', line 6

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