foreman_expire_hosts 5.0.0 → 5.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: 6b84a9475e315085398e8c35d6577d7644583a1063c9b72c5c323c3e59a08edb
4
- data.tar.gz: a71f5e3324d8caa9d7572c015331d1fc4b541ab720c14af5bce558bb408f3820
3
+ metadata.gz: 7a87b2c303a78750274b73d20e3d7113d0431353a699f80b6e86ef7e07ab179f
4
+ data.tar.gz: 3a93c88e92b00b7348c326546beab99e9d5655b859d72fbed82f250b6ad74f5a
5
5
  SHA512:
6
- metadata.gz: 712461bc58fb25679244d62258c65a82a844ba2d0366218aeef9551f3d03c8e01cc67c50dae3267bd2f53218550236afcf7b9297440c8b939533fb2892f864fd
7
- data.tar.gz: dfc0efce22d729a5389f61befc0b36b14f7b888df1274a6d748b05db5cda572d43b57351d3b47f14687fa0e3b08b9bee42f6f4eb5aefd8d53dd0844236b71c2c
6
+ metadata.gz: 74d7b446ffaac6353b3b82c29dc3f6474d161e00d2ecbd4231e15257b9589e6f7159a7badc141f97d05f0f035ee7236685faf0ef6c03603c771032edf6c99597
7
+ data.tar.gz: b6e522f9a6311a5d2abb3547b08625e1666479ed538f3757dd2a2fd50658a86d42914cda9f0d47d53773d3ab8058f80fc84cd8a5aeaf7f67f9bc2842bb920864
@@ -1,9 +1,17 @@
1
1
  module ForemanExpireHosts
2
2
  module HostsHelperExtensions
3
- def multiple_actions
4
- actions = super
5
- actions << [_('Change Expiration'), select_multiple_expiration_hosts_path] if authorized_for(:controller => :hosts, :action => :edit)
6
- actions
3
+ extend ActiveSupport::Concern
4
+
5
+ module Overrides
6
+ def multiple_actions
7
+ actions = super
8
+ actions << [_('Change Expiration'), select_multiple_expiration_hosts_path] if authorized_for(:controller => :hosts, :action => :select_multiple_expiration)
9
+ actions
10
+ end
11
+ end
12
+
13
+ included do
14
+ prepend Overrides
7
15
  end
8
16
 
9
17
  def host_expiry_warning_message(host)
@@ -30,10 +38,10 @@ module ForemanExpireHosts
30
38
  end
31
39
  end
32
40
 
33
- def datepicker_f(f, attr, options = {})
34
- field(f, attr, options) do
41
+ def datepicker_f(form, attr, options = {})
42
+ field(form, attr, options) do
35
43
  addClass options, 'form-control'
36
- date = f.text_field attr, options
44
+ date = form.text_field attr, options
37
45
  addon = input_group_addon('', :class => 'glyphicon glyphicon-calendar')
38
46
  input_group date, addon
39
47
  end
@@ -8,7 +8,15 @@ module ForemanExpireHosts
8
8
  end
9
9
 
10
10
  def destroy!
11
- subject.destroy!
11
+ # If Katello is installed, we can't just destroy the host
12
+ # but have to ask ForemanTasks to do this for us.
13
+ # See https://community.theforeman.org/t/how-to-properly-destroy-a-content-host/8621
14
+ # for reasoning.
15
+ if with_katello?
16
+ ForemanTasks.sync_task(::Actions::Katello::Host::Destroy, subject)
17
+ else
18
+ subject.destroy!
19
+ end
12
20
  rescue ActiveRecord::RecordNotDestroyed => invalid
13
21
  message = _('Failed to delete %{class_name} %{subject}: %{message} - Errors: %{errors}') % {
14
22
  :class_name => subject.class.name,
@@ -19,5 +27,14 @@ module ForemanExpireHosts
19
27
  Foreman::Logging.exception(message, invalid)
20
28
  false
21
29
  end
30
+
31
+ private
32
+
33
+ def with_katello?
34
+ Katello # rubocop:disable Lint/Void
35
+ true
36
+ rescue StandardError
37
+ false
38
+ end
22
39
  end
23
40
  end
@@ -40,7 +40,7 @@ module ForemanExpireHosts
40
40
 
41
41
  def update_notification
42
42
  find_notification
43
- .update_attributes(expired_at: blueprint.expired_at, :message => parsed_message)
43
+ .update(expired_at: blueprint.expired_at, :message => parsed_message)
44
44
  end
45
45
 
46
46
  def redeliver!
@@ -1,4 +1,4 @@
1
- require File.expand_path('../lib/foreman_expire_hosts/version', __FILE__)
1
+ require File.expand_path('lib/foreman_expire_hosts/version', __dir__)
2
2
  require 'date'
3
3
 
4
4
  Gem::Specification.new do |s|
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency 'deface'
23
23
 
24
24
  s.add_development_dependency 'rdoc'
25
- s.add_development_dependency 'rubocop', '0.52.0'
25
+ s.add_development_dependency 'rubocop', '0.54.0'
26
26
  end
@@ -19,7 +19,7 @@ module ForemanExpireHosts
19
19
  end
20
20
 
21
21
  initializer 'foreman_expire_hosts.load_default_settings', :before => :load_config_initializers do
22
- require_dependency File.expand_path('../../../app/models/setting/expire_hosts.rb', __FILE__) if (Setting.table_exists? rescue(false))
22
+ require_dependency File.expand_path('../../app/models/setting/expire_hosts.rb', __dir__) if (Setting.table_exists? rescue(false))
23
23
  end
24
24
 
25
25
  initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |_app|
@@ -1,3 +1,3 @@
1
1
  module ForemanExpireHosts
2
- VERSION = '5.0.0'.freeze
2
+ VERSION = '5.1.0'.freeze
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class HostsHelperTest < ActionView::TestCase
4
+ include HostsHelper
5
+ include ApplicationHelper
6
+
7
+ describe '#multiple_actions' do
8
+ test 'includes expire bulk action' do
9
+ assert_includes multiple_actions.map(&:first), 'Change Expiration'
10
+ end
11
+ end
12
+ end
@@ -22,5 +22,15 @@ module ForemanExpireHosts
22
22
  assert_equal 1, HostWithFailingCallbacks.all.count
23
23
  end
24
24
  end
25
+
26
+ describe 'with a host' do
27
+ let(:host) { FactoryBot.create(:host, :managed) }
28
+
29
+ test 'deletes a host' do
30
+ assert Host::Managed.find_by(id: host.id)
31
+ assert SafeDestroy.new(host).destroy!
32
+ refute Host::Managed.find_by(id: host.id)
33
+ end
34
+ end
25
35
  end
26
36
  end
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: 5.0.0
4
+ version: 5.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: 2018-01-15 00:00:00.000000000 Z
12
+ date: 2018-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bootstrap-datepicker-rails
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: 0.52.0
62
+ version: 0.54.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: 0.52.0
69
+ version: 0.54.0
70
70
  description: This Plugin will add new column expired_on to hosts to limit the lifetime
71
71
  of a host.
72
72
  email:
@@ -136,6 +136,7 @@ files:
136
136
  - test/factories/foreman_expire_hosts_factories.rb
137
137
  - test/functional/api/v2/hosts_controller_test.rb
138
138
  - test/functional/concerns/hosts_controller_extensions_test.rb
139
+ - test/helpers/hosts_helper_test.rb
139
140
  - test/lib/expire_hosts_notifications_test.rb
140
141
  - test/test_plugin_helper.rb
141
142
  - test/unit/concerns/host_extensions_test.rb
@@ -171,6 +172,7 @@ test_files:
171
172
  - test/factories/foreman_expire_hosts_factories.rb
172
173
  - test/functional/api/v2/hosts_controller_test.rb
173
174
  - test/functional/concerns/hosts_controller_extensions_test.rb
175
+ - test/helpers/hosts_helper_test.rb
174
176
  - test/lib/expire_hosts_notifications_test.rb
175
177
  - test/test_plugin_helper.rb
176
178
  - test/unit/concerns/host_extensions_test.rb