Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zeitwerk loader support #141

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ foreman-installer

| Foreman Version | Katello Version | Plugin Version |
| --------------- | --------------- | -------------- |
| 3.13 | 4.15 | ~> 4.0.0 |
| 3.7 | 4.9 | ~> 3.0.0 |
| 3.3 | 4.5 | ~> 2.0.0 |
| 3.1 | 4.3 | ~> 1.8.20\* |
| 3.0 | 4.2 | ~> 1.8.20 |
| 2.5 | 4.1 | ~> 1.8.20 |
| 2.3 | 3.18 | ~> 1.8.9 |
| 2.1 | 3.16 | ~> 1.8.5 |
| 2.0 | 3.16 | ~> 1.8.4 |
| 1.24 | 3.14 | ~> 1.8.0 |

\* If you are using foreman_scc_manager in version 1.8.20 and then upgrade to Katello 4.3, you need to manually run the following rake task on your Foreman instance: `foreman-rake foreman_scc_manager:setup_authentication_tokens`.

Expand All @@ -51,7 +48,7 @@ Fork and send a Pull Request. Thanks!

## Copyright

Copyright (c) 2023 ATIX AG - https://atix.de
Copyright (c) 2024 ATIX AG - https://atix.de

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
10 changes: 4 additions & 6 deletions app/models/concerns/recurring_logic_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module Concerns
nadjaheitmann marked this conversation as resolved.
Show resolved Hide resolved
module RecurringLogicExtensions
extend ActiveSupport::Concern
module RecurringLogicExtensions
extend ActiveSupport::Concern

included do
has_one :scc_account, :inverse_of => :foreman_tasks_recurring_logic, :class_name => 'SccAccount'
end
included do
has_one :scc_account, :inverse_of => :foreman_tasks_recurring_logic, :class_name => 'SccAccount'
end
end
1 change: 1 addition & 0 deletions foreman_scc_manager.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Gem::Specification.new do |s|
# Testing
s.add_development_dependency 'webmock'

s.add_dependency 'coffee-rails', '~> 5.0.0'
bastian-src marked this conversation as resolved.
Show resolved Hide resolved
s.add_dependency 'katello', '>= 3.16'
end
1 change: 1 addition & 0 deletions gemfile.d/katello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem 'katello', github: 'Katello/katello', branch: 'master'
163 changes: 80 additions & 83 deletions lib/foreman_scc_manager/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ module ForemanSccManager
class Engine < ::Rails::Engine
engine_name 'foreman_scc_manager'

config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
config.autoload_paths += Dir["#{config.root}/app/overrides"]

config.to_prepare do
ForemanTasks::RecurringLogic.include Concerns::RecurringLogicExtensions
ForemanTasks::RecurringLogic.include RecurringLogicExtensions
end

# Add any db migrations
Expand All @@ -20,84 +15,86 @@ class Engine < ::Rails::Engine
end
end

initializer 'foreman_scc_manager.register_plugin', :before => :finisher_hook do |_app|
Foreman::Plugin.register :foreman_scc_manager do
requires_foreman '>= 3.7'
requires_foreman_plugin 'katello', '>= 3.16.0'
register_gettext

precompile_assets 'foreman_scc_manager/scc_accounts.js'

apipie_documented_controllers ["#{ForemanSccManager::Engine.root}/app/controllers/api/v2/*.rb"]

# Add permissions
security_block :foreman_scc_manager do
permission :view_scc_accounts,
{ :scc_accounts => [:show, :index, :auto_complete_search],
:'api/v2/scc_accounts' => [:show, :index, :auto_complete_search] },
:resource_type => 'SccAccount'

permission :use_scc_accounts,
{ :scc_accounts => [:bulk_subscribe],
:'api/v2/scc_accounts' => [:bulk_subscribe, :bulk_subscribe_with_repos] },
:resource_type => 'SccAccount'

permission :new_scc_accounts,
{ :scc_accounts => [:new, :create],
:'api/v2/scc_accounts' => [:create] },
:resource_type => 'SccAccount'

permission :edit_scc_accounts,
{ :scc_accounts => [:edit, :update],
:'api/v2/scc_accounts' => [:update] },
:resource_type => 'SccAccount'

permission :delete_scc_accounts,
{ :scc_accounts => [:destroy],
:'api/v2/scc_accounts' => [:destroy] },
:resource_type => 'SccAccount'

permission :sync_scc_accounts,
{ :scc_accounts => [:sync],
:'api/v2/scc_accounts' => [:sync] },
:resource_type => 'SccAccount'

permission :test_connection_scc_accounts,
{ :scc_accounts => [:test_connection],
:'api/v2/scc_accounts' => [:test_connection] },
:resource_type => 'SccAccount'

permission :view_scc_products,
{ :scc_products => [:index, :show],
:'api/v2/scc_products' => [:index, :show] },
:resource_type => 'SccProduct'

permission :subscribe_scc_products,
{ :scc_products => [:subscribe, :unsubscribe],
:'api/v2/scc_products' => [:subscribe, :unsibscribe] },
:resource_type => 'SccProduct'
initializer 'foreman_scc_manager.register_plugin', :before => :finisher_hook do |app|
app.reloader.to_prepare do
Foreman::Plugin.register :foreman_scc_manager do
requires_foreman '>= 3.13'
requires_foreman_plugin 'katello', '>= 3.16.0'
bastian-src marked this conversation as resolved.
Show resolved Hide resolved
register_gettext

precompile_assets 'foreman_scc_manager/scc_accounts.js'

apipie_documented_controllers ["#{ForemanSccManager::Engine.root}/app/controllers/api/v2/*.rb"]

# Add permissions
security_block :foreman_scc_manager do
permission :view_scc_accounts,
{ :scc_accounts => [:show, :index, :auto_complete_search],
:'api/v2/scc_accounts' => [:show, :index, :auto_complete_search] },
:resource_type => 'SccAccount'

permission :use_scc_accounts,
{ :scc_accounts => [:bulk_subscribe],
:'api/v2/scc_accounts' => [:bulk_subscribe, :bulk_subscribe_with_repos] },
:resource_type => 'SccAccount'

permission :new_scc_accounts,
{ :scc_accounts => [:new, :create],
:'api/v2/scc_accounts' => [:create] },
:resource_type => 'SccAccount'

permission :edit_scc_accounts,
{ :scc_accounts => [:edit, :update],
:'api/v2/scc_accounts' => [:update] },
:resource_type => 'SccAccount'

permission :delete_scc_accounts,
{ :scc_accounts => [:destroy],
:'api/v2/scc_accounts' => [:destroy] },
:resource_type => 'SccAccount'

permission :sync_scc_accounts,
{ :scc_accounts => [:sync],
:'api/v2/scc_accounts' => [:sync] },
:resource_type => 'SccAccount'

permission :test_connection_scc_accounts,
{ :scc_accounts => [:test_connection],
:'api/v2/scc_accounts' => [:test_connection] },
:resource_type => 'SccAccount'

permission :view_scc_products,
{ :scc_products => [:index, :show],
:'api/v2/scc_products' => [:index, :show] },
:resource_type => 'SccProduct'

permission :subscribe_scc_products,
{ :scc_products => [:subscribe, :unsubscribe],
:'api/v2/scc_products' => [:subscribe, :unsibscribe] },
:resource_type => 'SccProduct'
end

# Add a new role called 'SccManager' if it doesn't exist
role 'SccManager',
%i[view_scc_accounts use_scc_accounts new_scc_accounts edit_scc_accounts
delete_scc_accounts sync_scc_accounts test_connection_scc_accounts
view_scc_products subscribe_scc_products],
'Role granting permissons to manage SUSE Subscriptions'

role 'SccViewer',
%i[view_scc_accounts use_scc_accounts sync_scc_accounts
create_products view_products subscribe_scc_products view_scc_products],
'Role granting permissons to view and use SUSE Subscriptions'

add_all_permissions_to_default_roles

# add menu entry
menu :top_menu, :scc_manager,
url_hash: { controller: :scc_accounts, action: :index },
caption: _('SUSE Subscriptions'),
parent: :content_menu,
after: :red_hat_subscriptions
end

# Add a new role called 'SccManager' if it doesn't exist
role 'SccManager',
%i[view_scc_accounts use_scc_accounts new_scc_accounts edit_scc_accounts
delete_scc_accounts sync_scc_accounts test_connection_scc_accounts
view_scc_products subscribe_scc_products],
'Role granting permissons to manage SUSE Subscriptions'

role 'SccViewer',
%i[view_scc_accounts use_scc_accounts sync_scc_accounts
create_products view_products subscribe_scc_products view_scc_products],
'Role granting permissons to view and use SUSE Subscriptions'

add_all_permissions_to_default_roles

# add menu entry
menu :top_menu, :scc_manager,
url_hash: { controller: :scc_accounts, action: :index },
caption: _('SUSE Subscriptions'),
parent: :content_menu,
after: :red_hat_subscriptions
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v2/scc_accounts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def scc_setup
put :update, params: { id: account.id, scc_account: { :base_url => '', :sync_date => Time.now, :interval => 'weekly' } }

assert_response :unprocessable_entity
assert_error_message "Base url can't be blank"
assert_error_message "Base URL can't be blank"
end

test 'new account SCC server connection-test' do
Expand Down