From 41fcc7ee1bd790f3bfa497ea09c1d0e3be7d594c Mon Sep 17 00:00:00 2001 From: Bernhard Suttner Date: Fri, 15 Dec 2023 18:04:05 +0100 Subject: [PATCH] Fix multiple actions --- .../hosts_helper_extension.rb | 9 --------- .../foreman_snapshot_management/hosts_helper.rb | 16 ++++++++++++++++ lib/foreman_snapshot_management/engine.rb | 8 ++++---- 3 files changed, 20 insertions(+), 13 deletions(-) delete mode 100644 app/helpers/concerns/foreman_snapshot_management/hosts_helper_extension.rb create mode 100644 app/helpers/foreman_snapshot_management/hosts_helper.rb diff --git a/app/helpers/concerns/foreman_snapshot_management/hosts_helper_extension.rb b/app/helpers/concerns/foreman_snapshot_management/hosts_helper_extension.rb deleted file mode 100644 index cc8edfb..0000000 --- a/app/helpers/concerns/foreman_snapshot_management/hosts_helper_extension.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module ForemanSnapshotManagement - module HostsHelperExtension - def multiple_actions - super + [[_('Create Snapshot'), select_multiple_host_snapshots_path]] - end - end -end diff --git a/app/helpers/foreman_snapshot_management/hosts_helper.rb b/app/helpers/foreman_snapshot_management/hosts_helper.rb new file mode 100644 index 0000000..2768b9e --- /dev/null +++ b/app/helpers/foreman_snapshot_management/hosts_helper.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module ForemanSnapshotManagement + module HostsHelper + def snapshot_multiple_actions + return [] unless can_create_snapshots? + [{ action: [_('Create Snapshot'), select_multiple_host_snapshots_path], priority: 1000 }] + end + + private + + def can_create_snapshots? + User.current.can?(:create_snapshots) + end + end +end diff --git a/lib/foreman_snapshot_management/engine.rb b/lib/foreman_snapshot_management/engine.rb index 648cea6..cc86cb8 100644 --- a/lib/foreman_snapshot_management/engine.rb +++ b/lib/foreman_snapshot_management/engine.rb @@ -6,7 +6,6 @@ class Engine < ::Rails::Engine config.autoload_paths += Dir["#{config.root}/app/models/concerns"] config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"] - config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"] initializer 'foreman_snapshot_management.register_plugin', before: :finisher_hook do |_app| Foreman::Plugin.register :foreman_snapshot_management do @@ -65,6 +64,10 @@ class Engine < ::Rails::Engine :partial => 'hosts/snapshots_tab', :onlyif => proc { |host| host&.uuid.present? && host&.compute_resource&.capable?(:snapshots) } end + + describe_host do + multiple_actions_provider :snapshot_multiple_actions + end end end @@ -86,9 +89,6 @@ class Engine < ::Rails::Engine # Include concerns in this config.to_prepare block config.to_prepare do - # Load Foreman extensions - ::HostsHelper.prepend ForemanSnapshotManagement::HostsHelperExtension - begin ::ForemanFogProxmox::Proxmox.prepend ForemanSnapshotManagement::ProxmoxExtensions