From 0b55fc00534c0b0c3318c85de569fe44c6f3660c Mon Sep 17 00:00:00 2001 From: ochnerd <148320557+ochnerd@users.noreply.github.com> Date: Fri, 31 May 2024 10:14:21 +0200 Subject: [PATCH] fix(hosts_helper): fix legacy ui --- .rubocop.yml | 3 +++ .../hosts_helper_extensions.rb | 26 ------------------- .../foreman_expire_hosts/hosts_helper.rb | 19 ++++++++++++++ lib/foreman_expire_hosts/engine.rb | 1 - 4 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb diff --git a/.rubocop.yml b/.rubocop.yml index 8f7044c..35c2c71 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,3 +11,6 @@ inherit_mode: Metrics/BlockLength: Exclude: - 'lib/foreman_expire_hosts/engine.rb' + +Style/FormatString: + EnforcedStyle: percent diff --git a/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb b/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb deleted file mode 100644 index 29eee02..0000000 --- a/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -module ForemanExpireHosts - module HostsHelperExtensions - extend ActiveSupport::Concern - - def host_expiry_warning_message(host) - return nil unless host.expires? - - if host.expired_past_grace_period? - message = _('This host has expired %s ago and needs to be deleted manually.') % time_ago_in_words(host.expired_on) - elsif host.expired? - message = _('This host has expired %{time_ago} ago and will be deleted on %{delete_date}.') % { :delete_date => l(host.expiration_grace_period_end_date), :time_ago => time_ago_in_words(host.expired_on) } - elsif host.expires_today? - message = _('This host will expire today.') - elsif host.pending_expiration? - message = _('This host will expire in %{distance_of_time} (on %{expire_date}).') % { :expire_date => l(host.expired_on), :distance_of_time => future_time_in_words(host.expired_on) } - end - message - end - - def future_time_in_words(to_time, options = {}) - distance_of_time_in_words(to_time, Time.current, options) - end - end -end diff --git a/app/helpers/foreman_expire_hosts/hosts_helper.rb b/app/helpers/foreman_expire_hosts/hosts_helper.rb index 6a57245..65c2e4a 100644 --- a/app/helpers/foreman_expire_hosts/hosts_helper.rb +++ b/app/helpers/foreman_expire_hosts/hosts_helper.rb @@ -12,5 +12,24 @@ def expire_hosts_host_multiple_actions end actions end + + def host_expiry_warning_message(host) + return nil unless host.expires? + + if host.expired_past_grace_period? + message = _('This host has expired %s ago and needs to be deleted manually.') % time_ago_in_words(host.expired_on) + elsif host.expired? + message = _('This host has expired %{time_ago} ago and will be deleted on %{delete_date}.') % { :delete_date => l(host.expiration_grace_period_end_date), :time_ago => time_ago_in_words(host.expired_on) } + elsif host.expires_today? + message = _('This host will expire today.') + elsif host.pending_expiration? + message = _('This host will expire in %{distance_of_time} (on %{expire_date}).') % { :expire_date => l(host.expired_on), :distance_of_time => future_time_in_words(host.expired_on) } + end + message + end + + def future_time_in_words(to_time, options = {}) + distance_of_time_in_words(to_time, Time.current, options) + end end end diff --git a/lib/foreman_expire_hosts/engine.rb b/lib/foreman_expire_hosts/engine.rb index 4e2fef2..d30ad9d 100644 --- a/lib/foreman_expire_hosts/engine.rb +++ b/lib/foreman_expire_hosts/engine.rb @@ -87,7 +87,6 @@ class Engine < ::Rails::Engine config.to_prepare do begin ::Host::Managed.include ForemanExpireHosts::HostExt - ::HostsHelper.include ForemanExpireHosts::HostsHelperExtensions ::HostsController.prepend ForemanExpireHosts::HostControllerExtensions ::AuditsHelper.include ForemanExpireHosts::AuditsHelperExtensions ::Api::V2::HostsController.include ForemanExpireHosts::Api::V2::HostsControllerExtensions