Skip to content

Commit

Permalink
fix(hosts_helper): fix legacy ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ochnerd authored May 31, 2024
1 parent 2765128 commit 0b55fc0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ inherit_mode:
Metrics/BlockLength:
Exclude:
- 'lib/foreman_expire_hosts/engine.rb'

Style/FormatString:
EnforcedStyle: percent

This file was deleted.

19 changes: 19 additions & 0 deletions app/helpers/foreman_expire_hosts/hosts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion lib/foreman_expire_hosts/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b55fc0

Please sign in to comment.