Module: ForemanPuppet::Extensions::User::PatchedMethods

Defined in:
app/models/concerns/foreman_puppet/extensions/user.rb

Instance Method Summary collapse

Instance Method Details

#visible_environmentsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/concerns/foreman_puppet/extensions/user.rb', line 11

def visible_environments
  authorized_scope = ForemanPuppet::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_env_ids = TaxableTaxonomy.where(taxable_type: 'ForemanPuppet::Environment').distinct.select(:taxable_id)
    untaxed_environments = ForemanPuppet::Environment.unscoped.where.not(id: untaxed_env_ids).pluck(:name)
    result += untaxed_environments
  end
  result
end