From ea824868788b1cc9d59f224e52b4c2fe6434ee32 Mon Sep 17 00:00:00 2001 From: Stejskal Leos Date: Thu, 17 Oct 2024 09:24:02 +0000 Subject: [PATCH] Fixes #37923 - Set HTTP proxy as default after creating --- .../v2/http_proxies_controller_extensions.rb | 17 ++++++++++++++++ .../http_proxies_controller_extensions.rb | 20 +++++++++++++++++++ .../_update_setting_input.html.erb | 16 +++++++++++++++ config/initializers/pagelets.rb | 6 ++++++ lib/katello/engine.rb | 3 +++ 5 files changed, 62 insertions(+) create mode 100644 app/controllers/katello/concerns/api/v2/http_proxies_controller_extensions.rb create mode 100644 app/controllers/katello/concerns/http_proxies_controller_extensions.rb create mode 100644 app/views/overrides/http_proxies/_update_setting_input.html.erb diff --git a/app/controllers/katello/concerns/api/v2/http_proxies_controller_extensions.rb b/app/controllers/katello/concerns/api/v2/http_proxies_controller_extensions.rb new file mode 100644 index 00000000000..2d2f8c5baca --- /dev/null +++ b/app/controllers/katello/concerns/api/v2/http_proxies_controller_extensions.rb @@ -0,0 +1,17 @@ +module Katello + module Concerns + module Api + module V2 + module HttpProxiesControllerExtensions + extend ::Apipie::DSL::Concern + + update_api(:create) do + param :http_proxy, Hash do + param :default_content_proxy, :bool, :required => false, :desc => N_('Set this HTTP proxy as the default content HTTP proxy') + end + end + end + end + end + end +end diff --git a/app/controllers/katello/concerns/http_proxies_controller_extensions.rb b/app/controllers/katello/concerns/http_proxies_controller_extensions.rb new file mode 100644 index 00000000000..303a9e11c8e --- /dev/null +++ b/app/controllers/katello/concerns/http_proxies_controller_extensions.rb @@ -0,0 +1,20 @@ +module Katello + module Concerns + module HttpProxiesControllerExtensions + extend ActiveSupport::Concern + + included do + after_action :update_content_default_http_proxy, only: :create + end + + private + + def update_content_default_http_proxy + return unless @http_proxy.persisted? + return unless ActiveRecord::Type::Boolean.new.deserialize(params.dig('http_proxy', 'default_content')) + + Setting[:content_default_http_proxy] = @http_proxy.name + end + end + end +end diff --git a/app/views/overrides/http_proxies/_update_setting_input.html.erb b/app/views/overrides/http_proxies/_update_setting_input.html.erb new file mode 100644 index 00000000000..a9141f4bcde --- /dev/null +++ b/app/views/overrides/http_proxies/_update_setting_input.html.erb @@ -0,0 +1,16 @@ +<% if @http_proxy.new_record? %> +
+
+ +
+ <%= check_box_tag 'http_proxy[default_content]', + '1', + params.dig('http_proxy', 'default_content') == '1', + id: 'http_proxy_default_content' %> + Set this proxy as the default for content, updating the 'Default HTTP Proxy' setting. +
+
+
+<% end %> diff --git a/config/initializers/pagelets.rb b/config/initializers/pagelets.rb index c1ec45f867e..f8f858998f2 100644 --- a/config/initializers/pagelets.rb +++ b/config/initializers/pagelets.rb @@ -4,3 +4,9 @@ :partial => "overrides/activation_keys/host_environment_select", :priority => 80 end + +Pagelets::Manager.with_key "http_proxies/_form" do |mgr| + mgr.add_pagelet :main_tab_fields, + :partial => "overrides/http_proxies/update_setting_input", + :priority => 80 +end diff --git a/lib/katello/engine.rb b/lib/katello/engine.rb index ee6014140f1..df2939152db 100644 --- a/lib/katello/engine.rb +++ b/lib/katello/engine.rb @@ -159,6 +159,7 @@ class Engine < ::Rails::Engine #Controller extensions ::HostsController.include Katello::Concerns::HostsControllerExtensions ::SmartProxiesController.include Katello::Concerns::SmartProxiesControllerExtensions + ::HttpProxiesController.include Katello::Concerns::HttpProxiesControllerExtensions ::RegistrationCommandsController.prepend Katello::Concerns::RegistrationCommandsControllerExtensions #Helper Extensions @@ -198,6 +199,8 @@ class Engine < ::Rails::Engine ::Api::V2::HostsBulkActionsController.include Katello::Concerns::Api::V2::HostsBulkActionsControllerExtensions ::Api::V2::HostgroupsController.include Katello::Concerns::Api::V2::HostgroupsControllerExtensions ::Api::V2::SmartProxiesController.include Katello::Concerns::Api::V2::SmartProxiesControllerExtensions + ::Api::V2::HttpProxiesController.include Katello::Concerns::HttpProxiesControllerExtensions + ::Api::V2::HttpProxiesController.include Katello::Concerns::Api::V2::HttpProxiesControllerExtensions ::Api::V2::RegistrationController.include ::Foreman::Controller::SmartProxyAuth ::Api::V2::RegistrationController.prepend Katello::Concerns::Api::V2::RegistrationControllerExtensions ::Api::V2::RegistrationCommandsController.include Katello::Concerns::Api::V2::RegistrationCommandsControllerExtensions