From 55c376d35ca1d4ca0e6156fe2e439bee9b632e25 Mon Sep 17 00:00:00 2001 From: Stejskal Leos Date: Wed, 18 Dec 2024 09:00:57 +0000 Subject: [PATCH] refs #37923 - Bug fixes & improvements for the Default HTTP proxy Follow up on PR#11183 with: * Unified naming of the parameter ('content_default_http_proxy') * On edit form showing information if the capsule is default * Fixed API + extended show with 'content_default_http_proxy' --- .../v2/http_proxies_controller_extensions.rb | 4 +-- .../http_proxies_controller_extensions.rb | 2 +- .../katello/concerns/http_proxy_extensions.rb | 4 +++ .../api/v2/http_proxies/show.json.rabl | 1 + .../_update_setting_input.html.erb | 30 ++++++++++--------- lib/katello/plugin.rb | 1 + 6 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 app/views/katello/api/v2/http_proxies/show.json.rabl 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 index 2d2f8c5baca..2839a6a82f9 100644 --- a/app/controllers/katello/concerns/api/v2/http_proxies_controller_extensions.rb +++ b/app/controllers/katello/concerns/api/v2/http_proxies_controller_extensions.rb @@ -5,9 +5,9 @@ module V2 module HttpProxiesControllerExtensions extend ::Apipie::DSL::Concern - update_api(:create) do + update_api(:create, :show) 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') + param :content_default_http_proxy, :bool, :required => false, :desc => N_('Set this HTTP proxy as the default content HTTP proxy') 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 index 303a9e11c8e..00049d9282c 100644 --- a/app/controllers/katello/concerns/http_proxies_controller_extensions.rb +++ b/app/controllers/katello/concerns/http_proxies_controller_extensions.rb @@ -11,7 +11,7 @@ module HttpProxiesControllerExtensions def update_content_default_http_proxy return unless @http_proxy.persisted? - return unless ActiveRecord::Type::Boolean.new.deserialize(params.dig('http_proxy', 'default_content')) + return unless ActiveRecord::Type::Boolean.new.deserialize(params.dig('http_proxy', 'content_default_http_proxy')) Setting[:content_default_http_proxy] = @http_proxy.name end diff --git a/app/models/katello/concerns/http_proxy_extensions.rb b/app/models/katello/concerns/http_proxy_extensions.rb index ad2ef8d9aa7..d12940d0ec3 100644 --- a/app/models/katello/concerns/http_proxy_extensions.rb +++ b/app/models/katello/concerns/http_proxy_extensions.rb @@ -84,6 +84,10 @@ def name_and_url uri.user = nil "#{name} (#{uri})" end + + def content_default_http_proxy? + Setting[:content_default_http_proxy] == name + end end end end diff --git a/app/views/katello/api/v2/http_proxies/show.json.rabl b/app/views/katello/api/v2/http_proxies/show.json.rabl new file mode 100644 index 00000000000..9e41a1adf72 --- /dev/null +++ b/app/views/katello/api/v2/http_proxies/show.json.rabl @@ -0,0 +1 @@ +node(:content_default_http_proxy) { |sp| sp.content_default_http_proxy? } diff --git a/app/views/overrides/http_proxies/_update_setting_input.html.erb b/app/views/overrides/http_proxies/_update_setting_input.html.erb index a9141f4bcde..991456abc43 100644 --- a/app/views/overrides/http_proxies/_update_setting_input.html.erb +++ b/app/views/overrides/http_proxies/_update_setting_input.html.erb @@ -1,16 +1,18 @@ -<% 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. -
+
+
+ +
+ <% if @http_proxy.new_record? %> + <%= check_box_tag 'http_proxy[content_default_http_proxy]', + '1', + params.dig('http_proxy', 'content_default_http_proxy') == '1', + id: 'content_default_http_proxy' %> + Set this proxy as the default for content, updating the 'Default HTTP Proxy' setting. + <% else %> + <%= @http_proxy.content_default_http_proxy? ? _('Yes') : _('No') %> + <% end %>
-<% end %> +
diff --git a/lib/katello/plugin.rb b/lib/katello/plugin.rb index 4c5ee25098e..a5a37dac5f7 100644 --- a/lib/katello/plugin.rb +++ b/lib/katello/plugin.rb @@ -298,6 +298,7 @@ extend_rabl_template 'api/v2/smart_proxies/main', 'katello/api/v2/smart_proxies/pulp_info' extend_rabl_template 'api/v2/hosts/show', 'katello/api/v2/hosts/host_collections' extend_rabl_template 'api/v2/hosts/show', 'katello/api/v2/hosts/show' + extend_rabl_template 'api/v2/http_proxies/show', 'katello/api/v2/http_proxies/show' # Katello variables for Host Registration extend_allowed_registration_vars :activation_keys