Skip to content

Commit

Permalink
Add Zeitwerk loader support
Browse files Browse the repository at this point in the history
  • Loading branch information
nadjaheitmann committed Oct 7, 2024
1 parent 6f66bde commit 6127f9c
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 176 deletions.
2 changes: 1 addition & 1 deletion app/controllers/ui_acd_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Controller to create JSON data to be used in react app
class UiAcdController < ::Api::V2::BaseController
class UIAcdController < ::Api::V2::BaseController
include ::ForemanAcd::Concerns::AppInstanceMixins

def app
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Add git_url column to ansible_playbook
class AddGitUrlToAnsiblePlaybooks < ActiveRecord::Migration[6.0]
class AddGitURLToAnsiblePlaybooks < ActiveRecord::Migration[6.0]
def change
add_column :acd_ansible_playbooks, :git_url, :string
end
Expand Down
174 changes: 164 additions & 10 deletions lib/foreman_acd/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ module ForemanAcd
class Engine < ::Rails::Engine
engine_name 'foreman_acd'

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

# Add any db migrations
initializer 'foreman_acd.load_app_instance_data' do |app|
ForemanAcd::Engine.paths['db/migrate'].existent.each do |path|
Expand All @@ -40,8 +32,170 @@ class Engine < ::Rails::Engine
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
end

initializer 'foreman_acd.register_plugin', :before => :finisher_hook do
require 'foreman_acd/plugin'
initializer 'foreman_acd.register_plugin', :before => :finisher_hook do |app|
app.reloader.to_prepare do
Foreman::Plugin.register :foreman_acd do
requires_foreman '>= 3.13'

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

# Menus
sub_menu :top_menu, :application, :caption => N_('Applications'), :after => :hosts_menu, :icon => 'pficon pficon-integration' do
menu :top_menu, :ansible_playbooks,
:url_hash => { :controller => :'foreman_acd/ansible_playbooks', :action => :index },
:caption => 'Ansible Playbooks'

menu :top_menu, :app_definitions,
:url_hash => { :controller => :'foreman_acd/app_definitions', :action => :index },
:caption => 'App Definitions'

menu :top_menu, :app_instances,
:url_hash => { :controller => :'foreman_acd/app_instances', :action => :index },
:caption => 'App Instances'
end

# Add permissions
security_block :foreman_acd do
permission :create_ansible_playbooks,
{ :'foreman_acd/ansible_playbooks' => [:new, :create],
:'foreman_acd/api/v2/ansible_playbooks' => [:create] },
:resource_type => 'ForemanAcd::AnsiblePlaybook'

permission :view_ansible_playbooks,
{ :'foreman_acd/ansible_playbooks' => [:index, :show, :auto_complete_search],
:'foreman_acd/api/v2/ansible_playbooks' => [:index, :show] },
:resource_type => 'ForemanAcd::AnsiblePlaybook'

permission :edit_ansible_playbooks,
{ :'foreman_acd/ansible_playbooks' => [:update, :edit, :sync_git_repo],
:'foreman_acd/api/v2/ansible_playbooks' => [:update] },
:resource_type => 'ForemanAcd::AnsiblePlaybook'

permission :destroy_ansible_playbooks,
{ :'foreman_acd/ansible_playbooks' => [:destroy],
:'foreman_acd/api/v2/ansible_playbooks' => [:destroy] },
:resource_type => 'ForemanAcd::AnsiblePlaybook'

permission :import_vars_ansible_playbooks,
{ :'foreman_acd/ansible_playbooks' => [:import_vars],
:'foreman_acd/api/v2/ansible_playbooks' => [:import_vars] },
:resource_type => 'ForemanAcd::AnsiblePlaybook'

permission :grab_ansible_playbooks,
{ :'foreman_acd/api/v2/ansible_playbooks' => [:grab] },
:resource_type => 'ForemanAcd::AnsiblePlaybook'

permission :create_app_definitions,
{ :'foreman_acd/app_definitions' => [:new, :create],
:'foreman_acd/api/v2/app_definitions' => [:create] },
:resource_type => 'ForemanAcd::AppDefinition'

permission :view_app_definitions,
{ :'foreman_acd/app_definitions' => [:index, :show, :auto_complete_search],
:'foreman_acd/api/v2/app_definitions' => [:index, :show] },
:resource_type => 'ForemanAcd::AppDefinition'

permission :edit_app_definitions,
{ :'foreman_acd/app_definitions' => [:update, :edit],
:'foreman_acd/api/v2/app_definitions' => [:update] },
:resource_type => 'ForemanAcd::AppDefinition'

permission :destroy_app_definitions,
{ :'foreman_acd/app_definitions' => [:destroy],
:'foreman_acd/api/v2/app_definitions' => [:destroy] },
:resource_type => 'ForemanAcd::AppDefinition'

permission :export_app_definitions,
{ :'foreman_acd/app_definitions' => [:export, :handle_file_upload],
:'foreman_acd/api/v2/app_definitions' => [:export] },
:resource_type => 'ForemanAcd::AppDefinition'

permission :import_app_definitions,
{ :'foreman_acd/app_definitions' => [:import],
:'foreman_acd/api/v2/app_definitions' => [:import] },
:resource_type => 'ForemanAcd::AppDefinition'

permission :create_app_instances,
{ :'foreman_acd/app_instances' => [:new, :create],
:'foreman_acd/api/v2/app_instances' => [:create] },
:resource_type => 'ForemanAcd::AppInstance'

permission :view_app_instances,
{ :'foreman_acd/app_instances' => [:index, :show, :auto_complete_search],
:'foreman_acd/api/v2/app_instances' => [:index, :show] },
:resource_type => 'ForemanAcd::AppInstance'

permission :edit_app_instances,
{ :'foreman_acd/app_instances' => [:update, :edit],
:'foreman_acd/api/v2/app_instances' => [:update] },
:resource_type => 'ForemanAcd::AppInstance'

permission :destroy_app_instances,
{ :'foreman_acd/app_instances' => [:destroy, :destroy_with_hosts],
:'foreman_acd/api/v2/app_instances' => [:destroy, :destroy_with_hosts] },
:resource_type => 'ForemanAcd::AppInstance'

permission :deploy_app_instances,
{ :'foreman_acd/app_instances' => [:deploy],
:'foreman_acd/api/v2/app_instances' => [:deploy] },
:resource_type => 'ForemanAcd::AppInstance'

permission :report_app_instances,
{ :'foreman_acd/app_instances' => [:report],
:'foreman_acd/api/v2/app_instances' => [:report] },
:resource_type => 'ForemanAcd::AppInstance'

permission :new_acd_configure_job,
{ :'foreman_acd/remote_execution' => [:new] },
:resource_type => 'ForemanAcd::AppInstance'

permission :create_acd_configure_job,
{ :'foreman_acd/remote_execution' => [:create] },
:resource_type => 'ForemanAcd::AppInstance'

permission :view_ui_acd,
{ :ui_acd => [:app, :foreman_data, :ansible_data, :validate_hostname, :report_data] }

permission :acd_foreman_hosts,
{ :'foreman_acd/app_instances' => [:create, :edit, :update, :deploy, :destroy_with_hosts, :destroy] },
:resource_type => 'ForemanAcd::ForemanHost'
end

# Manager Role
role 'Application Centric Deployment Manager', [:create_ansible_playbooks, :view_ansible_playbooks, :edit_ansible_playbooks,
:destroy_ansible_playbooks,
:import_vars_ansible_playbooks, :grab_ansible_playbooks,
:create_app_definitions, :view_app_definitions, :edit_app_definitions,
:destroy_app_definitions,
:export_app_definitions, :import_app_definitions,
:create_app_instances, :view_app_instances, :edit_app_instances,
:destroy_app_instances,
:deploy_app_instances,
:new_acd_configure_job, :create_acd_configure_job,
:report_app_instances,
:view_ui_acd,
:view_hosts, :build_hosts, :power_hosts, :create_hosts, :edit_hosts, :destroy_hosts, :console_hosts,
:view_job_invocations, :cancel_job_invocations, :create_job_invocations, :create_template_invocations,
:view_job_templates,
:view_foreman_tasks,
:acd_foreman_hosts, :view_smart_proxies]

# User Role
role 'Application Centric Deployment User', [:create_app_instances, :view_app_instances, :edit_app_instances,
:destroy_app_instances,
:deploy_app_instances,
:new_acd_configure_job, :create_acd_configure_job,
:report_app_instances,
:view_ui_acd,
:view_hosts, :build_hosts, :power_hosts, :create_hosts, :edit_hosts, :destroy_hosts, :console_hosts,
:view_job_invocations, :cancel_job_invocations, :create_job_invocations, :create_template_invocations,
:view_job_templates,
:view_foreman_tasks,
:acd_foreman_hosts, :view_smart_proxies]

add_all_permissions_to_default_roles
end
end
end

initializer 'foreman_acd.register_actions', :before => :finisher_hook do |_app|
Expand Down
Loading

0 comments on commit 6127f9c

Please sign in to comment.