File tree Expand file tree Collapse file tree
app/models/concerns/foreman_puppet/extensions
test/models/foreman_puppet Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,19 +9,7 @@ module User
99
1010 module PatchedMethods
1111 def visible_environments
12- authorized_scope = ForemanPuppet ::Environment . unscoped . authorized ( :view_environments )
13- authorized_scope = authorized_scope
14- . joins ( :taxable_taxonomies )
15- . where ( 'taxable_taxonomies.taxonomy_id' => taxonomy_ids [ :organizations ] + taxonomy_ids [ :locations ] )
16- result = authorized_scope . distinct . pluck ( :name )
17- if ::User . current . admin?
18- # Admin users can also see Environments that do not have any organization or location, even when
19- # organizations and locations are enabled.
20- untaxed_env_ids = TaxableTaxonomy . where ( taxable_type : 'ForemanPuppet::Environment' ) . distinct . select ( :taxable_id )
21- untaxed_environments = ForemanPuppet ::Environment . unscoped . where . not ( id : untaxed_env_ids ) . pluck ( :name )
22- result += untaxed_environments
23- end
24- result
12+ ForemanPuppet ::Environment . authorized ( :view_environments ) . pluck ( :name )
2513 end
2614 end
2715 end
Original file line number Diff line number Diff line change 11Foreman ::Plugin . register :foreman_puppet do
2- requires_foreman '>= 3.13 '
2+ requires_foreman '>= 3.19 '
33 register_gettext
44
55 # Add Global JS file for extending foreman-core components and routes
Original file line number Diff line number Diff line change @@ -24,8 +24,12 @@ class UserTest < ActiveSupport::TestCase
2424 end
2525
2626 test 'should show the list of environments visible as non-admin user' do
27- # Non-admin user only sees environments in a taxonomy at least
27+ # Non-admin user only sees environments in the same taxonomies at least
2828 setup_user 'view' , 'environments'
29+ # The user is in the same location as the environment, but in a
30+ # different org. The org mismatch would make the environment invisible
31+ # to the user.
32+ User . current . organizations << environment . organizations . first
2933 assert_equal [ environment . name ] , ::User . current . visible_environments
3034 end
3135 end
You can’t perform that action at this time.
0 commit comments