diff --git a/.rubocop.yml b/.rubocop.yml index f94eddf..df1fb6a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,6 +15,7 @@ Metrics/BlockLength: Max: 50 Exclude: - 'test/**/*.rb' + - 'lib/foreman_snapshot_management/engine.rb' Metrics/ClassLength: Max: 500 diff --git a/gemfile.d/proxmox.rb b/gemfile.d/proxmox.rb index aeeeafa..ed8fc0e 100644 --- a/gemfile.d/proxmox.rb +++ b/gemfile.d/proxmox.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true group :test do - gem 'foreman_fog_proxmox', '~> 0.15.0' + gem 'foreman_fog_proxmox', '~> 0.17.0' end diff --git a/lib/foreman_snapshot_management/engine.rb b/lib/foreman_snapshot_management/engine.rb index 3f42f8f..326ebea 100644 --- a/lib/foreman_snapshot_management/engine.rb +++ b/lib/foreman_snapshot_management/engine.rb @@ -4,70 +4,69 @@ module ForemanSnapshotManagement class Engine < ::Rails::Engine engine_name 'foreman_snapshot_management' - config.autoload_paths += Dir["#{config.root}/app/models/concerns"] - config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"] - - initializer 'foreman_snapshot_management.register_plugin', before: :finisher_hook do |_app| - Foreman::Plugin.register :foreman_snapshot_management do - requires_foreman '>= 3.7' - register_gettext - - # Add Global files for extending foreman-core components and routes - register_global_js_file 'global' - - apipie_documented_controllers ["#{ForemanSnapshotManagement::Engine.root}/app/controllers/api/v2/*.rb"] - - # Add permissions - security_block :foreman_snapshot_management do - permission :view_snapshots, { - :'foreman_snapshot_management/snapshots' => [:index], - :'api/v2/snapshots' => [:index, :show], - }, :resource_type => 'Host' - - permission :create_snapshots, { - :'foreman_snapshot_management/snapshots' => [:create, :select_multiple_host, :create_multiple_host], - :'api/v2/snapshots' => [:create], - }, :resource_type => 'Host' - - permission :edit_snapshots, { - :'foreman_snapshot_management/snapshots' => [:update], - :'api/v2/snapshots' => [:update], - }, :resource_type => 'Host' - - permission :destroy_snapshots, { - :'foreman_snapshot_management/snapshots' => [:destroy], - :'api/v2/snapshots' => [:destroy], - }, :resource_type => 'Host' - - permission :revert_snapshots, { - :'foreman_snapshot_management/snapshots' => [:revert], - :'api/v2/snapshots' => [:revert], - }, :resource_type => 'Host' - end - - # Adds roles if they do not exist - role 'Snapshot Viewer', - [:view_snapshots], - 'Role granting permission only to view snapshots for hosts' - role 'Snapshot Manager', - [ - :view_snapshots, - :create_snapshots, - :edit_snapshots, - :destroy_snapshots, - :revert_snapshots, - ], - 'Role granting permission to manage snapshots for hosts' - - extend_page('hosts/show') do |context| - context.add_pagelet :main_tabs, - :name => N_('Snapshots'), - :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 + initializer 'foreman_snapshot_management.register_plugin', before: :finisher_hook do |app| + app.reloader.to_prepare do + Foreman::Plugin.register :foreman_snapshot_management do + requires_foreman '>= 3.13' + register_gettext + + # Add Global files for extending foreman-core components and routes + register_global_js_file 'global' + + apipie_documented_controllers ["#{ForemanSnapshotManagement::Engine.root}/app/controllers/api/v2/*.rb"] + + # Add permissions + security_block :foreman_snapshot_management do + permission :view_snapshots, { + :'foreman_snapshot_management/snapshots' => [:index], + :'api/v2/snapshots' => [:index, :show], + }, :resource_type => 'Host' + + permission :create_snapshots, { + :'foreman_snapshot_management/snapshots' => [:create, :select_multiple_host, :create_multiple_host], + :'api/v2/snapshots' => [:create], + }, :resource_type => 'Host' + + permission :edit_snapshots, { + :'foreman_snapshot_management/snapshots' => [:update], + :'api/v2/snapshots' => [:update], + }, :resource_type => 'Host' + + permission :destroy_snapshots, { + :'foreman_snapshot_management/snapshots' => [:destroy], + :'api/v2/snapshots' => [:destroy], + }, :resource_type => 'Host' + + permission :revert_snapshots, { + :'foreman_snapshot_management/snapshots' => [:revert], + :'api/v2/snapshots' => [:revert], + }, :resource_type => 'Host' + end + + # Adds roles if they do not exist + role 'Snapshot Viewer', + [:view_snapshots], + 'Role granting permission only to view snapshots for hosts' + role 'Snapshot Manager', + [ + :view_snapshots, + :create_snapshots, + :edit_snapshots, + :destroy_snapshots, + :revert_snapshots, + ], + 'Role granting permission to manage snapshots for hosts' + + extend_page('hosts/show') do |context| + context.add_pagelet :main_tabs, + :name => N_('Snapshots'), + :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 end