foreman_expire_hosts 8.0.0 → 8.1.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: 74607c8b578a2549b16b8858c186dec33519fbec2f21c946e30d3b01b8c8ee13
4
+ data.tar.gz: d07c8068f7a85eb297d95c461abf65c1951409ba483c6bc5329c8abee318def5
5
5
  SHA512:
6
- metadata.gz: 15394668d731ba9c01b54e09ef5d13c1f6c3550938fd8fb4ee2188b696da77ad759a3df33ad80285aa378a2e463d496a92d80eb914b56a2af97655889060e23c
7
- data.tar.gz: bf2fca5f36c7eee30374e413d1c80f482a6fcf13d833a19e57fe4de61f7a14b731742d3064cd870bbd86533d5a5377c8ebe2217c1a70c94a6ade8dafd5bb9a2e
6
+ metadata.gz: 2c214dc0b884be13b4195ef443079db7a524839279aee288addace26dbd61e3d170e984f3468377dfba59cb89bb8521f4c18fa8667ad133bbb6b364e4514f1ab
7
+ data.tar.gz: 1e68621e1fb15baa5a94d40f080daecc55ad2fcbec4aedfd97b70fc5ec750c3198a3ff4e227743fe03e5cb95c603189dee628de2b265da8cb4d8ac7627643b07
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
 
@@ -22,12 +22,5 @@ module ForemanExpireHosts
22
22
  def future_time_in_words(to_time, options = {})
23
23
  distance_of_time_in_words(to_time, Time.current, options)
24
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
25
  end
33
26
  end
@@ -55,7 +55,7 @@ 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
59
59
  end
60
60
 
61
61
  def expired_past_grace_period?
@@ -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',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanExpireHosts
4
- VERSION = '8.0.0'
4
+ VERSION = '8.1.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
 
@@ -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.1.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: 2023-03-06 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.
@@ -146,6 +90,7 @@ files:
146
90
  - config/routes.rb
147
91
  - db/migrate/20150427101516_add_expiry_on_to_hosts.rb
148
92
  - db/migrate/20220923181700_fix_settings_category_to_dsl.rb
93
+ - db/migrate/20230112104438_change_expired_on_type.rb
149
94
  - db/seeds.d/80_expire_hosts_ui_notification.rb
150
95
  - extra/foreman_expire_hosts.cron
151
96
  - lib/expire_hosts_notifications.rb
@@ -183,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
128
  - !ruby/object:Gem::Version
184
129
  version: '0'
185
130
  requirements: []
186
- rubygems_version: 3.1.6
131
+ rubygems_version: 3.3.26
187
132
  signing_key:
188
133
  specification_version: 4
189
134
  summary: Foreman plugin for limiting host lifetime