foreman_expire_hosts 8.1.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74607c8b578a2549b16b8858c186dec33519fbec2f21c946e30d3b01b8c8ee13
4
- data.tar.gz: d07c8068f7a85eb297d95c461abf65c1951409ba483c6bc5329c8abee318def5
3
+ metadata.gz: 278bb558393256952a91c75901f1776bdab5314e43d9b10218ed06f1ac765fc9
4
+ data.tar.gz: b80fd1acc8b31a12b8be1f2464dd67633364db992a1dd414d06e0d792ede6f57
5
5
  SHA512:
6
- metadata.gz: 2c214dc0b884be13b4195ef443079db7a524839279aee288addace26dbd61e3d170e984f3468377dfba59cb89bb8521f4c18fa8667ad133bbb6b364e4514f1ab
7
- data.tar.gz: 1e68621e1fb15baa5a94d40f080daecc55ad2fcbec4aedfd97b70fc5ec750c3198a3ff4e227743fe03e5cb95c603189dee628de2b265da8cb4d8ac7627643b07
6
+ metadata.gz: 10c0283b3ecc5974c9faed866002002eef7c2ace0caf6549f0c311161e869bae7bb76f2d99fd8b068a6c8093186981e529feade1ffe3218028faf949b10bc950
7
+ data.tar.gz: 5251612576cb29e79686379c33029b9594521d89d0fa513912fa9c41361a619d5095c1a08bbdda4adc56104b7731f68d29833109154f72860d626b6fe576cf98
data/README.md CHANGED
@@ -20,6 +20,7 @@ This plugin will send two warning notifications before host expiry (see Settings
20
20
  | >= 1.18 | ~> 6.0 |
21
21
  | >= 1.24 | ~> 7.0 |
22
22
  | >= 3.0 | ~> 8.0 |
23
+ | >= 3.13 | ~> 9.0 |
23
24
 
24
25
  # Screenshots
25
26
  ![Expiry date field in host form](https://raw.githubusercontent.com/ingenico-group/screenshots/master/foreman_host_expiry/expiry-date-field-in-host-form.png)
@@ -12,5 +12,24 @@ module ForemanExpireHosts
12
12
  end
13
13
  actions
14
14
  end
15
+
16
+ def host_expiry_warning_message(host)
17
+ return nil unless host.expires?
18
+
19
+ if host.expired_past_grace_period?
20
+ message = _('This host has expired %s ago and needs to be deleted manually.') % time_ago_in_words(host.expired_on)
21
+ elsif host.expired?
22
+ 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) }
23
+ elsif host.expires_today?
24
+ message = _('This host will expire today.')
25
+ elsif host.pending_expiration?
26
+ 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) }
27
+ end
28
+ message
29
+ end
30
+
31
+ def future_time_in_words(to_time, options = {})
32
+ distance_of_time_in_words(to_time, Time.current, options)
33
+ end
15
34
  end
16
35
  end
@@ -10,11 +10,12 @@ module ExpireHostsNotifications
10
10
  ForemanExpireHosts::Action::StopExpiredHosts.new.engage
11
11
  end
12
12
 
13
- def deliver_expiry_warning_notification(num = 1) # notify1_days_before_expiry
13
+ # notify1_days_before_expiry
14
+ def deliver_expiry_warning_notification(num = 1)
14
15
  return unless [1, 2].include?(num)
15
16
 
16
17
  days_before_expiry = Setting["notify#{num}_days_before_host_expiry"].to_i
17
- expiry_date = (Date.today + days_before_expiry)
18
+ expiry_date = (Time.zone.today + days_before_expiry)
18
19
  notifiable_hosts = Host.with_expire_date(expiry_date).preload(:owner)
19
20
 
20
21
  ForemanExpireHosts::Notification::ExpiryWarning.new(
@@ -55,20 +55,20 @@ module ForemanExpireHosts
55
55
  def expiration_grace_period_end_date
56
56
  return nil unless expires?
57
57
 
58
- expired_on.to_date + Setting[:days_to_delete_after_host_expiration].to_i
58
+ expired_on.to_date + Setting[:days_to_delete_after_host_expiration].to_i.days
59
59
  end
60
60
 
61
61
  def expired_past_grace_period?
62
62
  return false unless expires?
63
63
 
64
- expiration_grace_period_end_date <= Date.today
64
+ expiration_grace_period_end_date.to_date <= Date.today
65
65
  end
66
66
 
67
67
  def pending_expiration?
68
68
  return false unless expires?
69
69
  return false if expired?
70
70
 
71
- expired_on - Setting['notify1_days_before_host_expiry'].to_i <= Date.today
71
+ expired_on.to_date - Setting['notify1_days_before_host_expiry'].to_i.days <= Date.today
72
72
  end
73
73
 
74
74
  def can_modify_expiry_date?
@@ -6,12 +6,6 @@ module ForemanExpireHosts
6
6
  class Engine < ::Rails::Engine
7
7
  engine_name 'foreman_expire_hosts'
8
8
 
9
- config.autoload_paths += Dir["#{config.root}/lib"]
10
- config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
11
- config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
12
- config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
13
- config.autoload_paths += Dir["#{config.root}/app/services"]
14
-
15
9
  # Add any db migrations
16
10
  initializer 'foreman_plugin_template.load_app_instance_data' do |app|
17
11
  ForemanExpireHosts::Engine.paths['db/migrate'].existent.each do |path|
@@ -19,67 +13,69 @@ module ForemanExpireHosts
19
13
  end
20
14
  end
21
15
 
22
- initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |_app|
23
- Foreman::Plugin.register :foreman_expire_hosts do
24
- requires_foreman '>= 3.0.0'
25
- register_custom_status HostStatus::ExpirationStatus
16
+ initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |app|
17
+ app.reloader.to_prepare do
18
+ Foreman::Plugin.register :foreman_expire_hosts do
19
+ requires_foreman '>= 3.13.0'
20
+ register_custom_status HostStatus::ExpirationStatus
26
21
 
27
- # strong parameters
28
- parameter_filter Host::Managed, :expired_on
22
+ # strong parameters
23
+ parameter_filter Host::Managed, :expired_on
29
24
 
30
- security_block :foreman_expire_hosts do
31
- permission :edit_host_expiry,
32
- {},
33
- :resource_type => 'Host'
34
- end
25
+ security_block :foreman_expire_hosts do
26
+ permission :edit_host_expiry,
27
+ {},
28
+ :resource_type => 'Host'
29
+ end
35
30
 
36
- # Extend built in permissions
37
- Foreman::AccessControl.permission(:edit_hosts).actions.concat [
38
- 'hosts/select_multiple_expiration',
39
- 'hosts/update_multiple_expiration'
40
- ]
31
+ # Extend built in permissions
32
+ Foreman::AccessControl.permission(:edit_hosts).actions.concat [
33
+ 'hosts/select_multiple_expiration',
34
+ 'hosts/update_multiple_expiration'
35
+ ]
41
36
 
42
- Setting::BLANK_ATTRS << 'host_expiry_email_recipients'
37
+ Setting::BLANK_ATTRS << 'host_expiry_email_recipients'
43
38
 
44
- settings do
45
- category(:expire_hosts, N_('Expire Hosts')) do
46
- setting('is_host_expiry_date_mandatory',
47
- type: :boolean,
48
- description: N_('Make expiry date field mandatory on host creation/update'),
49
- default: false,
50
- full_name: N_('Require host expiry date'))
51
- setting('can_owner_modify_host_expiry_date',
52
- type: :boolean,
53
- description: N_('Allow host owner to modify host expiry date field. If the field is false then admin only can edit expiry field'),
54
- default: false,
55
- full_name: N_('Host owner can modify host expiry date'))
56
- setting('notify1_days_before_host_expiry',
57
- type: :integer,
58
- description: N_('Send first notification to owner of hosts about his hosts expiring in given days. Must be integer only'),
59
- default: 7,
60
- full_name: N_('First expiry notification'))
61
- setting('notify2_days_before_host_expiry',
62
- type: :integer,
63
- description: N_('Send second notification to owner of hosts about his hosts expiring in given days. Must be integer only'),
64
- default: 1,
65
- full_name: N_('Second expiry notification'))
66
- setting('days_to_delete_after_host_expiration',
67
- type: :integer,
68
- description: N_('Delete expired hosts after given days of hosts expiry date. Must be integer only'),
69
- default: 3,
70
- full_name: N_('Expiry grace period in days'))
71
- setting('host_expiry_email_recipients',
72
- type: :string,
73
- description: N_('All notifications will be delivered to its owner. If any other users/admins need to receive those expiry warning notifications then those emails can be configured comma separated here.'),
74
- default: nil,
75
- full_name: N_('Expiry e-mail recipients'))
39
+ settings do
40
+ category(:expire_hosts, N_('Expire Hosts')) do
41
+ setting('is_host_expiry_date_mandatory',
42
+ type: :boolean,
43
+ description: N_('Make expiry date field mandatory on host creation/update'),
44
+ default: false,
45
+ full_name: N_('Require host expiry date'))
46
+ setting('can_owner_modify_host_expiry_date',
47
+ type: :boolean,
48
+ description: N_('Allow host owner to modify host expiry date field. If the field is false then admin only can edit expiry field'),
49
+ default: false,
50
+ full_name: N_('Host owner can modify host expiry date'))
51
+ setting('notify1_days_before_host_expiry',
52
+ type: :integer,
53
+ description: N_('Send first notification to owner of hosts about his hosts expiring in given days. Must be integer only'),
54
+ default: 7,
55
+ full_name: N_('First expiry notification'))
56
+ setting('notify2_days_before_host_expiry',
57
+ type: :integer,
58
+ description: N_('Send second notification to owner of hosts about his hosts expiring in given days. Must be integer only'),
59
+ default: 1,
60
+ full_name: N_('Second expiry notification'))
61
+ setting('days_to_delete_after_host_expiration',
62
+ type: :integer,
63
+ description: N_('Delete expired hosts after given days of hosts expiry date. Must be integer only'),
64
+ default: 3,
65
+ full_name: N_('Expiry grace period in days'))
66
+ setting('host_expiry_email_recipients',
67
+ type: :string,
68
+ description: N_('All notifications will be delivered to its owner. If any other users/admins need to receive those expiry warning notifications then those emails can be configured comma separated here.'), # rubocop:disable Layout/LineLength
69
+ default: nil,
70
+ full_name: N_('Expiry e-mail recipients'))
71
+ end
76
72
  end
77
- end
78
73
 
79
- extend_rabl_template 'api/v2/hosts/main', 'api/v2/hosts/expiration'
74
+ extend_rabl_template 'api/v2/hosts/main', 'api/v2/hosts/expiration'
80
75
 
81
- describe_host do
82
- multiple_actions_provider :expire_hosts_host_multiple_actions
76
+ describe_host do
77
+ multiple_actions_provider :expire_hosts_host_multiple_actions
78
+ end
83
79
  end
84
80
  end
85
81
  end
@@ -87,7 +83,6 @@ module ForemanExpireHosts
87
83
  config.to_prepare do
88
84
  begin
89
85
  ::Host::Managed.include ForemanExpireHosts::HostExt
90
- ::HostsHelper.include ForemanExpireHosts::HostsHelperExtensions
91
86
  ::HostsController.prepend ForemanExpireHosts::HostControllerExtensions
92
87
  ::AuditsHelper.include ForemanExpireHosts::AuditsHelperExtensions
93
88
  ::Api::V2::HostsController.include ForemanExpireHosts::Api::V2::HostsControllerExtensions
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanExpireHosts
4
- VERSION = '8.1.0'
4
+ VERSION = '9.0.0'
5
5
  end
@@ -5,7 +5,11 @@ require 'test_plugin_helper'
5
5
  class HostsHelperTest < ActionView::TestCase
6
6
  include HostsHelper
7
7
  include HostDescriptionHelper
8
- include PuppetRelatedHelper
8
+ # Foreman 3.7 dropped this via
9
+ # https://github.com/theforeman/foreman/commit/6cdb8c7a9ebd790537510213e43537a4a87189d6
10
+ # Foreman 3.9 bought it back via
11
+ # https://github.com/theforeman/foreman/commit/37a99c70ebd9e4d6f03af546dfe36e7678e2bcf3
12
+ include PuppetRelatedHelper if defined?(PuppetRelatedHelper)
9
13
  include ForemanExpireHosts::HostsHelper
10
14
  include ApplicationHelper
11
15
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_expire_hosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagarjuna Rachaneni
8
8
  - Timo Goebel
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2023-03-06 00:00:00.000000000 Z
11
+ date: 2025-06-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: deface
@@ -54,9 +53,9 @@ files:
54
53
  - app/controllers/concerns/foreman_expire_hosts/api/v2/hosts_controller_extensions.rb
55
54
  - app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb
56
55
  - app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb
57
- - app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb
58
56
  - app/helpers/expire_hosts_mailer_helper.rb
59
57
  - app/helpers/foreman_expire_hosts/hosts_helper.rb
58
+ - app/lib/expire_hosts_notifications.rb
60
59
  - app/mailers/expire_hosts_mailer.rb
61
60
  - app/models/concerns/foreman_expire_hosts/host_ext.rb
62
61
  - app/models/host_status/expiration_status.rb
@@ -93,7 +92,6 @@ files:
93
92
  - db/migrate/20230112104438_change_expired_on_type.rb
94
93
  - db/seeds.d/80_expire_hosts_ui_notification.rb
95
94
  - extra/foreman_expire_hosts.cron
96
- - lib/expire_hosts_notifications.rb
97
95
  - lib/foreman_expire_hosts.rb
98
96
  - lib/foreman_expire_hosts/engine.rb
99
97
  - lib/foreman_expire_hosts/version.rb
@@ -113,7 +111,6 @@ homepage: https://github.com/theforeman/foreman_expire_hosts
113
111
  licenses:
114
112
  - GPL-3.0
115
113
  metadata: {}
116
- post_install_message:
117
114
  rdoc_options: []
118
115
  require_paths:
119
116
  - lib
@@ -128,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
125
  - !ruby/object:Gem::Version
129
126
  version: '0'
130
127
  requirements: []
131
- rubygems_version: 3.3.26
132
- signing_key:
128
+ rubygems_version: 3.6.7
133
129
  specification_version: 4
134
130
  summary: Foreman plugin for limiting host lifetime
135
131
  test_files:
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ForemanExpireHosts
4
- module HostsHelperExtensions
5
- extend ActiveSupport::Concern
6
-
7
- def host_expiry_warning_message(host)
8
- return nil unless host.expires?
9
-
10
- if host.expired_past_grace_period?
11
- message = _('This host has expired %s ago and needs to be deleted manually.') % time_ago_in_words(host.expired_on)
12
- elsif host.expired?
13
- 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) }
14
- elsif host.expires_today?
15
- message = _('This host will expire today.')
16
- elsif host.pending_expiration?
17
- 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) }
18
- end
19
- message
20
- end
21
-
22
- def future_time_in_words(to_time, options = {})
23
- distance_of_time_in_words(to_time, Time.current, options)
24
- end
25
- end
26
- end