Skip to content

Commit de03f41

Browse files
adamruzickaofedoren
authored andcommitted
Fixes #39210 - Fix the tests
1 parent 875f7eb commit de03f41

3 files changed

Lines changed: 7 additions & 15 deletions

File tree

app/models/concerns/foreman_puppet/extensions/user.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff 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

lib/foreman_puppet/register.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Foreman::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

test/models/foreman_puppet/user_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)