From 4f8cf693dbdccbd9c6601d5ad2270837a8904906 Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Tue, 12 Sep 2023 06:10:17 +0200 Subject: [PATCH] Hide snapshots in case UUID is not set --- lib/foreman_snapshot_management/engine.rb | 2 +- .../SnapshotManagementCard.js | 21 +++++++++++-------- .../__tests__/SnapshotManagementCard.test.js | 1 + .../SnapshotManagementCard.test.js.snap | 17 +-------------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/foreman_snapshot_management/engine.rb b/lib/foreman_snapshot_management/engine.rb index 3f1e77a..648cea6 100644 --- a/lib/foreman_snapshot_management/engine.rb +++ b/lib/foreman_snapshot_management/engine.rb @@ -63,7 +63,7 @@ class Engine < ::Rails::Engine context.add_pagelet :main_tabs, :name => N_('Snapshots'), :partial => 'hosts/snapshots_tab', - :onlyif => proc { |host| host&.compute_resource&.capable?(:snapshots) } + :onlyif => proc { |host| host&.uuid.present? && host&.compute_resource&.capable?(:snapshots) } end end end diff --git a/webpack/components/SnapshotManagementCard/SnapshotManagementCard.js b/webpack/components/SnapshotManagementCard/SnapshotManagementCard.js index deb6900..6980c85 100644 --- a/webpack/components/SnapshotManagementCard/SnapshotManagementCard.js +++ b/webpack/components/SnapshotManagementCard/SnapshotManagementCard.js @@ -18,7 +18,7 @@ const SnapshotManagementCard = ({ hostDetails, ...props }) => { hostDetails?.capabilities?.includes('snapshot_include_quiesce') || false, }; - if (hostDetails?.id && hostDetails?.permissions) + if (hostDetails?.uuid && hostDetails?.id && hostDetails?.permissions) { children.push( { capabilities={capabilities} /> ); - return ( - - {children} - - ); + return ( + + {children} + + ); + } + return null; }; export default SnapshotManagementCard; @@ -46,6 +48,7 @@ SnapshotManagementCard.propTypes = { hostDetails: PropTypes.shape({ name: PropTypes.string, id: PropTypes.number, + uuid: PropTypes.string, capabilities: PropTypes.array, permissions: PropTypes.shape({ create_snapshots: PropTypes.bool, diff --git a/webpack/components/SnapshotManagementCard/__tests__/SnapshotManagementCard.test.js b/webpack/components/SnapshotManagementCard/__tests__/SnapshotManagementCard.test.js index ab83287..23503fd 100644 --- a/webpack/components/SnapshotManagementCard/__tests__/SnapshotManagementCard.test.js +++ b/webpack/components/SnapshotManagementCard/__tests__/SnapshotManagementCard.test.js @@ -5,6 +5,7 @@ import SnapshotManagementCard from '../SnapshotManagementCard'; const hostDetails = { id: 42, name: 'deep.thought', + uuid: '829aa26a-928f-11ee-b9d1-0242ac120002', permissions: { create_snapshots: true, edit_snapshots: false, diff --git a/webpack/components/SnapshotManagementCard/__tests__/__snapshots__/SnapshotManagementCard.test.js.snap b/webpack/components/SnapshotManagementCard/__tests__/__snapshots__/SnapshotManagementCard.test.js.snap index 88510d2..85b5eaa 100644 --- a/webpack/components/SnapshotManagementCard/__tests__/__snapshots__/SnapshotManagementCard.test.js.snap +++ b/webpack/components/SnapshotManagementCard/__tests__/__snapshots__/SnapshotManagementCard.test.js.snap @@ -114,19 +114,4 @@ exports[`SnapshotManagementCard renders with VMWare capabilities 1`] = ` `; -exports[`SnapshotManagementCard renders without optional Props 1`] = ` - -`; +exports[`SnapshotManagementCard renders without optional Props 1`] = `""`;