Skip to content

Commit

Permalink
Merge pull request #105 from ATIX-AG/zeitwerk_support
Browse files Browse the repository at this point in the history
Add Zeitwerk loader support
  • Loading branch information
nadjaheitmann authored Oct 21, 2024
2 parents 863b50a + 9dc6f22 commit e744580
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 65 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Metrics/BlockLength:
Max: 50
Exclude:
- 'test/**/*.rb'
- 'lib/foreman_snapshot_management/engine.rb'

Metrics/ClassLength:
Max: 500
Expand Down
2 changes: 1 addition & 1 deletion gemfile.d/proxmox.rb
Original file line number Diff line number Diff line change
@@ -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
127 changes: 63 additions & 64 deletions lib/foreman_snapshot_management/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e744580

Please sign in to comment.