foreman_expire_hosts 8.0.0 → 8.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c1855fd3586ff4abdc25e11e58c006a503c83acc12628890ce4d307ebf113b9
4
- data.tar.gz: c5ce62b9345649f1fd7365b0181ef83e53a93086f3b31435498b12eb6af0ce5c
3
+ metadata.gz: b3e5b913f8041ef79d3fdcb5572d9e0f5a04acb96ac6d18622bf2e4c064e7bf9
4
+ data.tar.gz: 29203939087fc0aa319796c0f5b8cca08cd65b92e3a7f6d2708eb4d6d35fa8f8
5
5
  SHA512:
6
- metadata.gz: 15394668d731ba9c01b54e09ef5d13c1f6c3550938fd8fb4ee2188b696da77ad759a3df33ad80285aa378a2e463d496a92d80eb914b56a2af97655889060e23c
7
- data.tar.gz: bf2fca5f36c7eee30374e413d1c80f482a6fcf13d833a19e57fe4de61f7a14b731742d3064cd870bbd86533d5a5377c8ebe2217c1a70c94a6ade8dafd5bb9a2e
6
+ metadata.gz: e8ae87316f890b0b9ffbb0d6ed9aaa97394871806a08b6e840b565565da321d5ca89cc7887388d2c4557d96552528146231d0791e476cc069962ed9b41d5bd20
7
+ data.tar.gz: fceaa7eb6ad7a554c5e3697ebfe69740d28f102313585c818b640a97d5225339c3deac030172722c530ab1e7600ce97900d4e7eea51606a326721c94290a2329
data/README.md CHANGED
@@ -19,6 +19,7 @@ This plugin will send two warning notifications before host expiry (see Settings
19
19
  | >= 1.17 | ~> 5.0 |
20
20
  | >= 1.18 | ~> 6.0 |
21
21
  | >= 1.24 | ~> 7.0 |
22
+ | >= 3.0 | ~> 8.0 |
22
23
 
23
24
  # Screenshots
24
25
  ![Expiry date field in host form](https://raw.githubusercontent.com/ingenico-group/screenshots/master/foreman_host_expiry/expiry-date-field-in-host-form.png)
@@ -55,13 +55,8 @@ module ForemanExpireHosts
55
55
 
56
56
  def expiration_date
57
57
  @expiration_date ||= begin
58
- year = params['host']['expired_on(1i)']
59
- month = params['host']['expired_on(2i)']
60
- day = params['host']['expired_on(3i)']
61
-
62
- return if year.empty? && month.empty? && day.empty?
63
-
64
- Date.parse("#{year}-#{month}-#{day}")
58
+ expired_on = params[:host][:expired_on]
59
+ expired_on.present? ? Date.parse(expired_on) : nil
65
60
  end
66
61
  end
67
62
 
@@ -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
@@ -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 + 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?
@@ -41,15 +41,15 @@ module HostStatus
41
41
  def to_label(_options = {})
42
42
  case to_status
43
43
  when OK
44
- N_('Expires on %s') % I18n.l(host.expired_on)
44
+ N_('Expires on %s') % I18n.l(host.expired_on.to_date)
45
45
  when EXPIRES_TODAY
46
46
  N_('Expires today')
47
47
  when IN_GRACE_PERIOD
48
- N_('Expired on %s, in grace period') % I18n.l(host.expired_on)
48
+ N_('Expired on %s, in grace period') % I18n.l(host.expired_on.to_date)
49
49
  when EXPIRED
50
- N_('Expired on %s') % I18n.l(host.expired_on)
50
+ N_('Expired on %s') % I18n.l(host.expired_on.to_date)
51
51
  else
52
- N_('Pending expiration on %s') % I18n.l(host.expired_on)
52
+ N_('Pending expiration on %s') % I18n.l(host.expired_on.to_date)
53
53
  end
54
54
  end
55
55
 
@@ -33,7 +33,7 @@ module ForemanExpireHosts
33
33
  private
34
34
 
35
35
  def with_katello?
36
- Katello # rubocop:disable Lint/Void
36
+ Katello::VERSION # rubocop:disable Lint/Void
37
37
  true
38
38
  rescue StandardError
39
39
  false
@@ -7,9 +7,6 @@
7
7
  <th>
8
8
  <%= _('Host group') %>
9
9
  </th>
10
- <th>
11
- <%= _('Environment') %>
12
- </th>
13
10
  <th>
14
11
  <%= _('Expiration Date') %>
15
12
  </th>
@@ -28,9 +25,6 @@
28
25
  <td class="hosts-rows">
29
26
  <%= host.hostgroup %>
30
27
  </td>
31
- <td class="hosts-rows">
32
- <%= host.environment %>
33
- </td>
34
28
  <td class="hosts-rows">
35
29
  <%= "#{l(host.expired_on)} (#{relative_date(host.expired_on)})" if host.expires? %>
36
30
  </td>
@@ -1,13 +1,12 @@
1
- <%= datepicker_f f, :expired_on,
2
- {
3
- :label => _('Expires on'),
4
- :autocomplete => false,
5
- :include_blank => true,
6
- :use_month_numbers => false,
7
- :start_year => Date.today.year,
8
- :help_block => ('<span class="pficon-warning-triangle-o"></span> '.html_safe + _('You are not allowed to change the expiry date of this host.') unless @host.can_modify_expiry_date?),
9
- :disabled => !@host.can_modify_expiry_date?,
10
- :help_inline => popover('Auto Expiry', _('Expired hosts will be deleted automatically after the grace period has passed.') + '<br>'.html_safe +
11
- _('If you do not want this host to expire and do not want it to be deleted automatically, do not specify an expiry date.'))
12
- }
13
- %>
1
+ <div class="form-group">
2
+ <label class="col-md-2 control-label"><%= _('Expires on') %></label>
3
+ <% if @host.can_modify_expiry_date? %>
4
+ <div class="col-md-4">
5
+ <%= react_component('DatePicker', { value: @host.expired_on, name: 'host[expired_on]', placement: 'bottom' }.to_json) %>
6
+ <%= content_tag(:span, _('Expired hosts will be deleted automatically after the grace period has passed. If you do not want this host to expire and do not want it to be deleted automatically, do not specify an expiry date.'), class: 'help-block help-inline') %>
7
+ </div>
8
+ <% else %>
9
+ <%= content_tag(:span, @host.expired_on&.to_s(:long), class: 'col-md-4') %>
10
+ <%= content_tag(:span, _('You are not allowed to change the expiry date of this host.'), class: 'help-block help-inline') %>
11
+ <% end %>
12
+ </div>
@@ -1,18 +1,9 @@
1
1
  <%= render 'selected_hosts', :hosts => @hosts %>
2
2
 
3
- <%= form_for :host, :url => update_multiple_expiration_hosts_path(:host_ids => params[:host_ids]) do |f| %>
4
-
5
- <%= _('Hosts will be deleted automatically on the given expiry date. Leave blank to clear expiration date.') %>
6
-
7
- <%= datepicker_f f, :expired_on,
8
- {
9
- :autocomplete => false,
10
- :include_blank => true,
11
- :use_month_numbers => false,
12
- :start_year => Date.today.year
13
- },
14
- {
15
- :onchange => 'tfm.hosts.table.toggleMultipleOkButton(this);'
16
- }
17
- %>
3
+ <%= form_for :host, html: { style: 'padding-bottom: 250px;' }, :url => update_multiple_expiration_hosts_path(:host_ids => params[:host_ids]) do |f| %>
4
+ <%= date_local_f f, :expired_on,
5
+ label: _('Expired on'),
6
+ label_help: _('Hosts will be deleted automatically on the given expiry date. Leave blank to clear expiration date.'),
7
+ placement: 'bottom'
8
+ %>
18
9
  <% end %>
@@ -2,6 +2,6 @@
2
2
 
3
3
  class FixSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
4
4
  def up
5
- Setting.where(category: 'Setting::ExpireHost').update_all(category: 'Setting')
5
+ Setting.where(category: 'Setting::ExpireHost').update_all(category: 'Setting') if column_exists?(:settings, :category)
6
6
  end
7
7
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ChangeExpiredOnType < ActiveRecord::Migration[6.0]
4
+ def up
5
+ change_column :hosts, :expired_on, :datetime
6
+ end
7
+
8
+ def down
9
+ change_column :hosts, :expired_on, :date
10
+ end
11
+ end
@@ -39,6 +39,8 @@ module ForemanExpireHosts
39
39
  'hosts/update_multiple_expiration'
40
40
  ]
41
41
 
42
+ Setting::BLANK_ATTRS << 'host_expiry_email_recipients'
43
+
42
44
  settings do
43
45
  category(:expire_hosts, N_('Expire Hosts')) do
44
46
  setting('is_host_expiry_date_mandatory',
@@ -85,7 +87,6 @@ module ForemanExpireHosts
85
87
  config.to_prepare do
86
88
  begin
87
89
  ::Host::Managed.include ForemanExpireHosts::HostExt
88
- ::HostsHelper.include ForemanExpireHosts::HostsHelperExtensions
89
90
  ::HostsController.prepend ForemanExpireHosts::HostControllerExtensions
90
91
  ::AuditsHelper.include ForemanExpireHosts::AuditsHelperExtensions
91
92
  ::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.0.0'
4
+ VERSION = '8.2.0'
5
5
  end
@@ -25,24 +25,9 @@ namespace :test do
25
25
  end
26
26
  end
27
27
 
28
- namespace :foreman_expire_hosts do
29
- task :rubocop => :environment do
30
- begin
31
- require 'rubocop/rake_task'
32
- RuboCop::RakeTask.new(:rubocop_foreman_expire_hosts) do |task|
33
- task.patterns = ["#{ForemanExpireHosts::Engine.root}/app/**/*.rb",
34
- "#{ForemanExpireHosts::Engine.root}/lib/**/*.rb",
35
- "#{ForemanExpireHosts::Engine.root}/test/**/*.rb"]
36
- end
37
- rescue StandardError
38
- puts 'Rubocop not loaded.'
39
- end
40
-
41
- Rake::Task['rubocop_foreman_expire_hosts'].invoke
42
- end
43
- end
44
-
45
28
  Rake::Task[:test].enhance ['test:foreman_expire_hosts']
46
29
 
47
30
  load 'tasks/jenkins.rake'
48
- Rake::Task['jenkins:unit'].enhance ['test:foreman_expire_hosts', 'foreman_expire_hosts:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
31
+ if Rake::Task.task_defined?(:'jenkins:unit')
32
+ Rake::Task['jenkins:unit'].enhance ['test:foreman_expire_hosts']
33
+ end
@@ -4,9 +4,9 @@ require 'test_plugin_helper'
4
4
 
5
5
  class HostsControllerTest < ActionController::TestCase
6
6
  setup do
7
+ Setting['host_details_ui'] = false if Setting['host_details_ui']
7
8
  User.current = users(:admin)
8
9
  disable_orchestration
9
- setup_settings
10
10
  end
11
11
 
12
12
  describe 'host creation' do
@@ -20,13 +20,11 @@ class HostsControllerTest < ActionController::TestCase
20
20
  :domain_id => domains(:mydomain).id,
21
21
  :operatingsystem_id => operatingsystems(:redhat).id,
22
22
  :architecture_id => architectures(:x86_64).id,
23
- :environment_id => environments(:production).id,
24
23
  :subnet_id => subnets(:one).id,
25
24
  :medium_id => media(:one).id,
26
25
  :pxe_loader => 'Grub2 UEFI',
27
26
  :realm_id => realms(:myrealm).id,
28
27
  :disk => 'empty partition',
29
- :puppet_proxy_id => smart_proxies(:puppetmaster).id,
30
28
  :root_pass => 'xybxa6JUkz63w',
31
29
  :location_id => taxonomies(:location1).id,
32
30
  :organization_id => taxonomies(:organization1).id,
@@ -53,7 +51,7 @@ class HostsControllerTest < ActionController::TestCase
53
51
  describe 'setting expiration date on multiple hosts' do
54
52
  before do
55
53
  as_admin do
56
- @hosts = FactoryBot.create_list(:host, 2, :with_puppet)
54
+ @hosts = FactoryBot.create_list(:host, 2)
57
55
  end
58
56
  @request.env['HTTP_REFERER'] = hosts_path
59
57
  end
@@ -70,7 +68,7 @@ class HostsControllerTest < ActionController::TestCase
70
68
  test 'should set expiration date' do
71
69
  expiration_date = Date.today + 14
72
70
  params = { :host_ids => @hosts.map(&:id),
73
- :host => { 'expired_on(1i)' => expiration_date.day.to_s, 'expired_on(2i)' => expiration_date.month.to_s, 'expired_on(3i)' => expiration_date.year.to_s } }
71
+ :host => { 'expired_on' => expiration_date.strftime('%Y-%m-%d') } }
74
72
 
75
73
  post :update_multiple_expiration, params: params, session: set_session_user.merge(:user => users(:admin).id)
76
74
 
@@ -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
 
@@ -7,7 +7,6 @@ class ExpireHostsNotificationsTest < ActiveSupport::TestCase
7
7
  include NotificationBlueprintSeeds
8
8
 
9
9
  setup do
10
- setup_settings
11
10
  ActionMailer::Base.deliveries.clear
12
11
  end
13
12
 
@@ -16,10 +16,6 @@ require File.join(
16
16
  # Foreman's setup doesn't handle cleaning up for Minitest::Spec
17
17
  DatabaseCleaner.strategy = :transaction
18
18
 
19
- def setup_settings
20
- Setting::ExpireHosts.load_defaults
21
- end
22
-
23
19
  class Minitest::Spec
24
20
  before :each do
25
21
  DatabaseCleaner.start
@@ -7,7 +7,6 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
7
7
 
8
8
  setup do
9
9
  User.current = FactoryBot.build(:user, :admin)
10
- setup_settings
11
10
  end
12
11
 
13
12
  context 'without required expiration date' do
@@ -3,10 +3,6 @@
3
3
  require 'test_plugin_helper'
4
4
 
5
5
  class ExpireHostMailerTest < ActionMailer::TestCase
6
- setup do
7
- setup_settings
8
- end
9
-
10
6
  let(:recipient) { FactoryBot.create(:user, :with_mail) }
11
7
  let(:hosts) { FactoryBot.create_list(:host, 2, :managed) }
12
8
 
@@ -84,7 +80,7 @@ class ExpireHostMailerTest < ActionMailer::TestCase
84
80
 
85
81
  test 'mail is delivered to admin address' do
86
82
  assert_nil recipient.mail
87
- assert_equal ['root@some.host.fqdn'], mail.to
83
+ assert_equal [Setting[:administrator]], mail.to
88
84
  end
89
85
  end
90
86
  end
@@ -30,7 +30,6 @@ module ForemanExpireHosts
30
30
 
31
31
  context 'with edit_hosts and owner permission' do
32
32
  setup do
33
- setup_settings
34
33
  FactoryBot.create(:filter, :role => role, :permissions => [edit_permission])
35
34
  end
36
35
  let(:hosts) { FactoryBot.create_list(:host, 2, :owner => user) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_expire_hosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0
4
+ version: 8.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagarjuna Rachaneni
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-10-24 00:00:00.000000000 Z
12
+ date: 2024-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deface
@@ -39,62 +39,6 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: rubocop
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 0.80.0
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 0.80.0
56
- - !ruby/object:Gem::Dependency
57
- name: rubocop-minitest
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: 0.7.0
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: 0.7.0
70
- - !ruby/object:Gem::Dependency
71
- name: rubocop-performance
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: 1.5.2
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: 1.5.2
84
- - !ruby/object:Gem::Dependency
85
- name: rubocop-rails
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: 2.4.2
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: 2.4.2
98
42
  description: |
99
43
  A Foreman plugin that allows hosts to expire at a configurable date.
100
44
  Hosts will be shut down and automatically deleted after a grace period.
@@ -110,7 +54,6 @@ files:
110
54
  - app/controllers/concerns/foreman_expire_hosts/api/v2/hosts_controller_extensions.rb
111
55
  - app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb
112
56
  - app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb
113
- - app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb
114
57
  - app/helpers/expire_hosts_mailer_helper.rb
115
58
  - app/helpers/foreman_expire_hosts/hosts_helper.rb
116
59
  - app/mailers/expire_hosts_mailer.rb
@@ -146,6 +89,7 @@ files:
146
89
  - config/routes.rb
147
90
  - db/migrate/20150427101516_add_expiry_on_to_hosts.rb
148
91
  - db/migrate/20220923181700_fix_settings_category_to_dsl.rb
92
+ - db/migrate/20230112104438_change_expired_on_type.rb
149
93
  - db/seeds.d/80_expire_hosts_ui_notification.rb
150
94
  - extra/foreman_expire_hosts.cron
151
95
  - lib/expire_hosts_notifications.rb
@@ -183,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
127
  - !ruby/object:Gem::Version
184
128
  version: '0'
185
129
  requirements: []
186
- rubygems_version: 3.1.6
130
+ rubygems_version: 3.2.3
187
131
  signing_key:
188
132
  specification_version: 4
189
133
  summary: Foreman plugin for limiting host lifetime
@@ -1,33 +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
-
26
- def datepicker_f(form, attr, options = {}, html_options = {})
27
- field(form, attr, options) do
28
- addClass options, 'form-control'
29
- form.date_select(attr, options, html_options)
30
- end
31
- end
32
- end
33
- end