diff --git a/app/views/katello/api/v2/hosts/base.json.rabl b/app/views/katello/api/v2/hosts/base.json.rabl index b7f80309087..f337ab2a016 100644 --- a/app/views/katello/api/v2/hosts/base.json.rabl +++ b/app/views/katello/api/v2/hosts/base.json.rabl @@ -4,6 +4,15 @@ object @resource @facet = @resource.content_facet attributes :id, :name, :description + +node :operatingsystem_family do |resource| + resource.operatingsystem.family +end + +node :operatingsystem_major do |resource| + resource.operatingsystem.major +end + if @facet node :content_view do content_view = @facet&.single_content_view diff --git a/lib/katello/plugin.rb b/lib/katello/plugin.rb index bda664feb42..2370486f791 100644 --- a/lib/katello/plugin.rb +++ b/lib/katello/plugin.rb @@ -303,6 +303,7 @@ extend_rabl_template 'api/v2/smart_proxies/main', 'katello/api/v2/smart_proxies/pulp_info' extend_rabl_template 'api/v2/hosts/show', 'katello/api/v2/hosts/host_collections' + extend_rabl_template 'api/v2/hosts/show', 'katello/api/v2/hosts/show' # Katello variables for Host Registration extend_allowed_registration_vars :activation_keys diff --git a/test/controllers/api/v2/host_subscriptions_controller_test.rb b/test/controllers/api/v2/host_subscriptions_controller_test.rb index 8a6a302eaa5..3e4b74de3ee 100644 --- a/test/controllers/api/v2/host_subscriptions_controller_test.rb +++ b/test/controllers/api/v2/host_subscriptions_controller_test.rb @@ -8,7 +8,7 @@ class Api::V2::HostSubscriptionsControllerBase < ActionController::TestCase tests Katello::Api::V2::HostSubscriptionsController def models - @host = FactoryBot.create(:host, :with_subscription) + @host = FactoryBot.create(:host, :with_subscription, :with_operatingsystem) users(:restricted).update_attribute(:organizations, [@host.organization]) users(:restricted).update_attribute(:locations, [@host.location]) @pool = katello_pools(:pool_one) diff --git a/test/controllers/api/v2/hosts_controller_test.rb b/test/controllers/api/v2/hosts_controller_test.rb index 7ed9e25a579..2852c53b883 100644 --- a/test/controllers/api/v2/hosts_controller_test.rb +++ b/test/controllers/api/v2/hosts_controller_test.rb @@ -12,7 +12,7 @@ def models @environment = katello_environments(:library) @dev = katello_environments(:dev) @cv2 = katello_content_views(:library_view_no_version) - @host = FactoryBot.create(:host) + @host = FactoryBot.create(:host, :with_operatingsystem) end def host_index_and_show(host) @@ -32,26 +32,26 @@ def host_show(host, smart_proxy) end def test_content_and_subscriptions - host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view, + host = FactoryBot.create(:host, :with_content, :with_subscription, :with_operatingsystem, :content_view => @content_view, :lifecycle_environment => @environment) host_index_and_show(host) end def test_with_content - host = FactoryBot.create(:host, :with_content, :content_view => @content_view, + host = FactoryBot.create(:host, :with_content, :with_operatingsystem, :content_view => @content_view, :lifecycle_environment => @environment) host_index_and_show(host) end def test_no_content_view_environments - host = FactoryBot.create(:host, :with_content, :with_subscription) + host = FactoryBot.create(:host, :with_content, :with_subscription, :with_operatingsystem) assert_empty host.content_facet.content_view_environments host_index_and_show(host) end def test_content_facet_attributes_assigned_as_cve - host = FactoryBot.create(:host, :with_content, :with_subscription, + host = FactoryBot.create(:host, :with_content, :with_subscription, :with_operatingsystem, :content_view => @content_view, :lifecycle_environment => @environment) Katello::Host::SubscriptionFacet.any_instance.expects(:backend_update_needed?).returns(false) orig_cves = host.content_facet.content_view_environment_ids.to_a @@ -110,7 +110,7 @@ def test_host_update_with_invalid_env end def test_with_subscriptions - host = FactoryBot.create(:host, :with_subscription) + host = FactoryBot.create(:host, :with_subscription, :with_operatingsystem) host_index_and_show(host) end @@ -122,7 +122,7 @@ def test_update_subscription_facet Katello::Candlepin::Consumer.any_instance.stubs(:virtual_guests).returns([]) Katello::Candlepin::Consumer.any_instance.stubs(:installed_products).returns([]) - host = FactoryBot.create(:host, :with_subscription) + host = FactoryBot.create(:host, :with_subscription, :with_operatingsystem) host.subscription_facet.update!(:autoheal => true, :installed_products_attributes => [{:product_name => 'foo', :version => '6', :product_id => '69'}]) @@ -136,7 +136,7 @@ def test_update_subscription_facet def test_with_smartproxy smart_proxy = FactoryBot.create(:smart_proxy, :features => [FactoryBot.create(:feature, name: 'Pulp')]) - host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view, + host = FactoryBot.create(:host, :with_content, :with_subscription, :with_operatingsystem, :content_view => @content_view, :lifecycle_environment => @environment, :content_source => smart_proxy) host_show(host, smart_proxy) end diff --git a/test/factories/host_factory.rb b/test/factories/host_factory.rb index de89b845255..8249fe17f7a 100644 --- a/test/factories/host_factory.rb +++ b/test/factories/host_factory.rb @@ -6,6 +6,10 @@ content_source { nil } end + trait :with_operatingsystem do + operatingsystem + end + trait :with_content do association :content_facet, :factory => :content_facet, :strategy => :build diff --git a/webpack/components/extensions/HostDetails/Tabs/DebsTab/DebsTab.js b/webpack/components/extensions/HostDetails/Tabs/DebsTab/DebsTab.js index 3fa5572f856..cc0a89bc5d8 100644 --- a/webpack/components/extensions/HostDetails/Tabs/DebsTab/DebsTab.js +++ b/webpack/components/extensions/HostDetails/Tabs/DebsTab/DebsTab.js @@ -45,12 +45,7 @@ import { hasRequiredPermissions as can, import SortableColumnHeaders from '../../../../Table/components/SortableColumnHeaders'; import { useRexJobPolling } from '../RemoteExecutionHooks'; -export const hideDebsTab = ({ hostDetails }) => { - const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+|\D+)/); - if (!osMatch) return false; - const [, os] = osMatch; - return !(osMatch && os.match(/Debian|Ubuntu/i)); -}; +export const hideDebsTab = ({ hostDetails }) => !(hostDetails?.operatingsystem_family === 'Debian'); const invokeRexJobs = ['create_job_invocations']; const createBookmarks = ['create_bookmarks']; diff --git a/webpack/components/extensions/HostDetails/Tabs/ModuleStreamsTab/ModuleStreamsTab.js b/webpack/components/extensions/HostDetails/Tabs/ModuleStreamsTab/ModuleStreamsTab.js index d3ff74425f2..bf2842a0837 100644 --- a/webpack/components/extensions/HostDetails/Tabs/ModuleStreamsTab/ModuleStreamsTab.js +++ b/webpack/components/extensions/HostDetails/Tabs/ModuleStreamsTab/ModuleStreamsTab.js @@ -47,14 +47,7 @@ import { userPermissionsFromHostDetails, } from '../../hostDetailsHelpers'; -const moduleStreamSupported = ({ os, version }) => - os.match(/RedHat|RHEL|CentOS|Rocky|AlmaLinux|Oracle Linux/i) && Number(version) > 7; -export const hideModuleStreamsTab = ({ hostDetails }) => { - const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+)/); - if (!osMatch) return false; - const [, os, version] = osMatch; - return !(osMatch && moduleStreamSupported({ os, version })); -}; +export const hideModuleStreamsTab = ({ hostDetails }) => !(hostDetails?.operatingsystem_family === 'Redhat' && Number(hostDetails?.operatingsystem_major > 7)); const EnabledIcon = ({ streamText, streamInstallStatus, upgradable }) => { switch (true) { diff --git a/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js b/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js index 789a9e8b52b..aacd9035d0d 100644 --- a/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js +++ b/webpack/components/extensions/HostDetails/Tabs/PackagesTab/PackagesTab.js @@ -50,12 +50,7 @@ import { runSubmanRepos } from '../../Cards/ContentViewDetailsCard/HostContentVi const invokeRexJobs = ['create_job_invocations']; const createBookmarks = ['create_bookmarks']; -export const hidePackagesTab = ({ hostDetails }) => { - const osMatch = hostDetails?.operatingsystem_name?.match(/(\D+) (\d+|\D+)/); - if (!osMatch) return false; - const [, os] = osMatch; - return !(osMatch && os.match(/RedHat|RHEL|CentOS|Rocky|AlmaLinux|Alma|Oracle Linux|Oracle|Suse Linux Enterprise Server|SLES/i)); -}; +export const hidePackagesTab = ({ hostDetails }) => !(hostDetails?.operatingsystem_family?.match(/RedHat|SUSE/i)); const UpdateVersionsSelect = ({ packageName,