foreman_expire_hosts 4.0.0 → 5.0.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
- SHA1:
3
- metadata.gz: 93ce6b56c3992acaf75ce33279400688b6feb3c6
4
- data.tar.gz: c5ebb3c23813c35e438c1e636aaa0f89c265035a
2
+ SHA256:
3
+ metadata.gz: 6b84a9475e315085398e8c35d6577d7644583a1063c9b72c5c323c3e59a08edb
4
+ data.tar.gz: a71f5e3324d8caa9d7572c015331d1fc4b541ab720c14af5bce558bb408f3820
5
5
  SHA512:
6
- metadata.gz: 3c96161b39033fa298be9570693b7f216e8745cd7f615f54055119dcd63c7e2f0c8123e1a40f334bad43f4819233bd8e4c3636daef9c00168ca69bb4986d0044
7
- data.tar.gz: 17c238e649d88559d2e7708ae0a35b31604d7a201df5721b4ff231c6fe1d4bfc8cac21170a6e2b63b27685eb633b3958a9931f6c9b4489f81bf8ac0aaa697680
6
+ metadata.gz: 712461bc58fb25679244d62258c65a82a844ba2d0366218aeef9551f3d03c8e01cc67c50dae3267bd2f53218550236afcf7b9297440c8b939533fb2892f864fd
7
+ data.tar.gz: dfc0efce22d729a5389f61befc0b36b14f7b888df1274a6d748b05db5cda572d43b57351d3b47f14687fa0e3b08b9bee42f6f4eb5aefd8d53dd0844236b71c2c
data/.rubocop.yml CHANGED
@@ -2,8 +2,10 @@ inherit_from:
2
2
  - .rubocop_todo.yml
3
3
 
4
4
  AllCops:
5
+ TargetRubyVersion: 2.2
6
+ TargetRailsVersion: 5.1
5
7
  Exclude:
6
- - 'doc/plugins/**'
8
+ - 'Rakefile'
7
9
 
8
10
  Rails:
9
11
  Enabled: true
@@ -15,10 +17,6 @@ Rails/Date:
15
17
  Style/Documentation:
16
18
  Enabled: false
17
19
 
18
- # Force before_filter until upgrade to Rails 4
19
- Rails/ActionFilter:
20
- EnforcedStyle: filter
21
-
22
20
  Metrics/MethodLength:
23
21
  Max: 40
24
22
 
@@ -53,9 +51,6 @@ Style/EachWithObject:
53
51
  Metrics/ParameterLists:
54
52
  Enabled: false
55
53
 
56
- Rails/HttpPositionalArguments:
57
- Enabled: false
58
-
59
54
  Style/SymbolArray:
60
55
  Enabled: false
61
56
 
@@ -74,7 +69,5 @@ Rails/HasManyOrHasOneDependent:
74
69
  Style/CommentedKeyword:
75
70
  Enabled: false
76
71
 
77
-
78
- # May be enabled for Foreman >= 1.16
79
- Rails/ApplicationRecord:
72
+ Rails/LexicallyScopedActionFilter:
80
73
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -6,11 +6,6 @@
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
10
- Lint/UselessAssignment:
11
- Exclude:
12
- - 'app/models/concerns/foreman_expire_hosts/host_ext.rb'
13
-
14
9
  # Offense count: 12
15
10
  Metrics/AbcSize:
16
11
  Max: 51
data/README.md CHANGED
@@ -16,6 +16,7 @@ This plugin will send two warning notifications before host expiry (see Settings
16
16
  | >= 1.13 | ~> 2.1 |
17
17
  | >= 1.15 | ~> 3.0 |
18
18
  | >= 1.16 | ~> 4.0 |
19
+ | >= 1.17 | ~> 5.0 |
19
20
 
20
21
  # Screenshots
21
22
  ![Expiry date field in host form](https://raw.githubusercontent.com/ingenico-group/screenshots/master/foreman_host_expiry/expiry-date-field-in-host-form.png)
@@ -0,0 +1,15 @@
1
+ module ForemanExpireHosts
2
+ module Api
3
+ module V2
4
+ module HostsControllerExtensions
5
+ extend Apipie::DSL::Concern
6
+
7
+ update_api(:create, :update) do
8
+ param :host, Hash do
9
+ param :expired_on, String, :desc => 'Expiry date'
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,8 +2,8 @@ module ForemanExpireHosts
2
2
  module HostControllerExtensions
3
3
  def self.prepended(base)
4
4
  base.class_eval do
5
- before_filter :validate_multiple_expiration, :only => :update_multiple_expiration
6
- before_filter :find_multiple_with_expire_hosts, :only => [:select_multiple_expiration, :update_multiple_expiration]
5
+ before_action :validate_multiple_expiration, :only => :update_multiple_expiration
6
+ before_action :find_multiple_with_expire_hosts, :only => [:select_multiple_expiration, :update_multiple_expiration]
7
7
  alias_method :find_multiple_with_expire_hosts, :find_multiple
8
8
  end
9
9
  end
@@ -2,9 +2,7 @@ module ForemanExpireHosts
2
2
  module HostsHelperExtensions
3
3
  def multiple_actions
4
4
  actions = super
5
- if authorized_for(:controller => :hosts, :action => :edit)
6
- actions << [_('Change Expiration'), select_multiple_expiration_hosts_path]
7
- end
5
+ actions << [_('Change Expiration'), select_multiple_expiration_hosts_path] if authorized_for(:controller => :hosts, :action => :edit)
8
6
  actions
9
7
  end
10
8
 
@@ -7,7 +7,7 @@ module ForemanExpireHosts
7
7
 
8
8
  validates :expired_on, :presence => true, :if => -> { Setting[:is_host_expiry_date_mandatory] }
9
9
 
10
- has_one :expiration_status_object, :class_name => 'HostStatus::ExpirationStatus', :foreign_key => 'host_id'
10
+ has_one :expiration_status_object, :class_name => 'HostStatus::ExpirationStatus', :foreign_key => 'host_id', :inverse_of => :host
11
11
 
12
12
  before_validation :refresh_expiration_status
13
13
 
@@ -23,17 +23,13 @@ module ForemanExpireHosts
23
23
  def validate_expired_on
24
24
  if self.expires?
25
25
  begin
26
- unless expired_on.to_s.to_date > Date.today
27
- errors.add(:expired_on, _('must be in the future'))
28
- end
29
- rescue StandardError => e
26
+ errors.add(:expired_on, _('must be in the future')) unless expired_on.to_s.to_date > Date.today
27
+ rescue StandardError
30
28
  errors.add(:expired_on, _('is invalid'))
31
29
  end
32
30
  end
33
31
  if self.changed.include?('expired_on')
34
- unless can_modify_expiry_date?
35
- errors.add(:expired_on, _('no permission to edit'))
36
- end
32
+ errors.add(:expired_on, _('no permission to edit')) unless can_modify_expiry_date?
37
33
  end
38
34
  true
39
35
  end
@@ -0,0 +1 @@
1
+ attributes :expired_on
@@ -1,4 +1,4 @@
1
- class AddExpiryOnToHosts < ActiveRecord::Migration
1
+ class AddExpiryOnToHosts < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :hosts, :expired_on, :date unless column_exists? :hosts, :expired_on
4
4
  end
@@ -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.51.0'
25
+ s.add_development_dependency 'rubocop', '0.52.0'
26
26
  end
@@ -24,7 +24,7 @@ module ForemanExpireHosts
24
24
 
25
25
  initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |_app|
26
26
  Foreman::Plugin.register :foreman_expire_hosts do
27
- requires_foreman '>= 1.16'
27
+ requires_foreman '>= 1.17'
28
28
  register_custom_status HostStatus::ExpirationStatus
29
29
 
30
30
  # strong parameters
@@ -38,6 +38,8 @@ module ForemanExpireHosts
38
38
  { :hosts => [:select_multiple_expiration, :update_multiple_expiration] },
39
39
  :resource_type => 'Host'
40
40
  end
41
+
42
+ extend_rabl_template 'api/v2/hosts/main', 'api/v2/hosts/expiration'
41
43
  end
42
44
  end
43
45
 
@@ -47,6 +49,7 @@ module ForemanExpireHosts
47
49
  HostsHelper.send :include, ForemanExpireHosts::HostsHelperExtensions
48
50
  HostsController.send :prepend, ForemanExpireHosts::HostControllerExtensions
49
51
  AuditsHelper.send :include, ForemanExpireHosts::AuditsHelperExtensions
52
+ ::Api::V2::HostsController.send :include, ForemanExpireHosts::Api::V2::HostsControllerExtensions
50
53
  rescue StandardError => e
51
54
  Rails.logger.warn "ForemanExpireHosts: skipping engine hook (#{e})"
52
55
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanExpireHosts
2
- VERSION = '4.0.0'.freeze
2
+ VERSION = '5.0.0'.freeze
3
3
  end
@@ -43,6 +43,4 @@ end
43
43
  Rake::Task[:test].enhance ['test:foreman_expire_hosts']
44
44
 
45
45
  load 'tasks/jenkins.rake'
46
- if Rake::Task.task_defined?(:'jenkins:unit')
47
- Rake::Task['jenkins:unit'].enhance ['test:foreman_expire_hosts', 'foreman_expire_hosts:rubocop']
48
- end
46
+ Rake::Task['jenkins:unit'].enhance ['test:foreman_expire_hosts', 'foreman_expire_hosts:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
@@ -0,0 +1,17 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class Api::V2::HostsControllerTest < ActionController::TestCase
4
+ let(:host) do
5
+ as_admin do
6
+ FactoryBot.create(:host, :expires_in_a_year)
7
+ end
8
+ end
9
+
10
+ test 'should show individual record with expiry data' do
11
+ get :show, params: { :id => host.to_param }
12
+ assert_response :success
13
+ show_response = ActiveSupport::JSON.decode(@response.body)
14
+ assert !show_response.empty?
15
+ assert_equal host.expired_on, show_response['expired_on'].to_date
16
+ end
17
+ end
@@ -11,27 +11,25 @@ class HostsControllerTest < ActionController::TestCase
11
11
  test 'new host with expiration date' do
12
12
  expiration_date = Date.today + 14
13
13
  assert_difference 'Host.count' do
14
- post :create, {
15
- :host => {
16
- :name => 'myotherfullhost',
17
- :mac => 'aabbecddee06',
18
- :ip => '2.3.4.125',
19
- :domain_id => domains(:mydomain).id,
20
- :operatingsystem_id => operatingsystems(:redhat).id,
21
- :architecture_id => architectures(:x86_64).id,
22
- :environment_id => environments(:production).id,
23
- :subnet_id => subnets(:one).id,
24
- :medium_id => media(:one).id,
25
- :pxe_loader => 'Grub2 UEFI',
26
- :realm_id => realms(:myrealm).id,
27
- :disk => 'empty partition',
28
- :puppet_proxy_id => smart_proxies(:puppetmaster).id,
29
- :root_pass => 'xybxa6JUkz63w',
30
- :location_id => taxonomies(:location1).id,
31
- :organization_id => taxonomies(:organization1).id,
32
- :expired_on => expiration_date
33
- }
34
- }, set_session_user
14
+ post :create, params: { :host => {
15
+ :name => 'myotherfullhost',
16
+ :mac => 'aabbecddee06',
17
+ :ip => '2.3.4.125',
18
+ :domain_id => domains(:mydomain).id,
19
+ :operatingsystem_id => operatingsystems(:redhat).id,
20
+ :architecture_id => architectures(:x86_64).id,
21
+ :environment_id => environments(:production).id,
22
+ :subnet_id => subnets(:one).id,
23
+ :medium_id => media(:one).id,
24
+ :pxe_loader => 'Grub2 UEFI',
25
+ :realm_id => realms(:myrealm).id,
26
+ :disk => 'empty partition',
27
+ :puppet_proxy_id => smart_proxies(:puppetmaster).id,
28
+ :root_pass => 'xybxa6JUkz63w',
29
+ :location_id => taxonomies(:location1).id,
30
+ :organization_id => taxonomies(:organization1).id,
31
+ :expired_on => expiration_date
32
+ } }, session: set_session_user
35
33
  end
36
34
  h = Host.search_for('myotherfullhost').first
37
35
  assert_equal expiration_date, h.expired_on
@@ -44,7 +42,7 @@ class HostsControllerTest < ActionController::TestCase
44
42
 
45
43
  test 'should add expiration date to host' do
46
44
  expiration_date = Date.today + 14
47
- put :update, { :id => host.name, :host => { :expired_on => expiration_date } }, set_session_user
45
+ put :update, params: { :id => host.name, :host => { :expired_on => expiration_date } }, session: set_session_user
48
46
  h = Host.find(host.id)
49
47
  assert_equal expiration_date, h.expired_on
50
48
  end
@@ -60,7 +58,7 @@ class HostsControllerTest < ActionController::TestCase
60
58
 
61
59
  test 'show a host selection' do
62
60
  host_ids = @hosts.map(&:id)
63
- xhr :post, :select_multiple_expiration, { :host_ids => host_ids }, set_session_user
61
+ post :select_multiple_expiration, params: { :host_ids => host_ids }, session: set_session_user, xhr: true
64
62
  assert_response :success
65
63
  @hosts.each do |host|
66
64
  assert response.body =~ /#{host.name}/m
@@ -72,8 +70,7 @@ class HostsControllerTest < ActionController::TestCase
72
70
  params = { :host_ids => @hosts.map(&:id),
73
71
  :host => { :expired_on => expiration_date } }
74
72
 
75
- post :update_multiple_expiration, params,
76
- set_session_user.merge(:user => users(:admin).id)
73
+ post :update_multiple_expiration, params: params, session: set_session_user.merge(:user => users(:admin).id)
77
74
 
78
75
  assert_empty flash[:error]
79
76
 
@@ -86,8 +83,7 @@ class HostsControllerTest < ActionController::TestCase
86
83
  params = { :host_ids => @hosts.map(&:id),
87
84
  :host => { :expired_on => '' } }
88
85
 
89
- post :update_multiple_expiration, params,
90
- set_session_user.merge(:user => users(:admin).id)
86
+ post :update_multiple_expiration, params: params, session: set_session_user.merge(:user => users(:admin).id)
91
87
 
92
88
  assert_empty flash[:error]
93
89
 
@@ -2,7 +2,7 @@ require 'test_plugin_helper'
2
2
 
3
3
  module ForemanExpireHosts
4
4
  class SafeDestroyTest < ActiveSupport::TestCase
5
- class HostWithFailingCallbacks < ActiveRecord::Base
5
+ class HostWithFailingCallbacks < ApplicationRecord
6
6
  self.table_name = 'hosts'
7
7
  self.inheritance_column = nil
8
8
 
@@ -11,7 +11,7 @@ module ForemanExpireHosts
11
11
  private
12
12
 
13
13
  def cancel
14
- false
14
+ throw(:abort)
15
15
  end
16
16
  end
17
17
 
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: 4.0.0
4
+ version: 5.0.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: 2017-12-01 00:00:00.000000000 Z
12
+ date: 2018-01-15 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.51.0
62
+ version: 0.52.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.51.0
69
+ version: 0.52.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:
@@ -87,6 +87,7 @@ files:
87
87
  - app/assets/javascripts/foreman_expire_hosts/application.js
88
88
  - app/assets/javascripts/foreman_expire_hosts/datepicker_for_host_expired_on_field.js
89
89
  - app/assets/stylesheets/foreman_expire_hosts/application.scss
90
+ - app/controllers/concerns/foreman_expire_hosts/api/v2/hosts_controller_extensions.rb
90
91
  - app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb
91
92
  - app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb
92
93
  - app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb
@@ -113,6 +114,7 @@ files:
113
114
  - app/services/foreman_expire_hosts/ui_notifications/hosts/base.rb
114
115
  - app/services/foreman_expire_hosts/ui_notifications/hosts/expiry_warning.rb
115
116
  - app/services/foreman_expire_hosts/ui_notifications/hosts/stopped_host.rb
117
+ - app/views/api/v2/hosts/expiration.json.rabl
116
118
  - app/views/expire_hosts_mailer/_hosts_table.html.erb
117
119
  - app/views/expire_hosts_mailer/deleted_hosts_notification.html.erb
118
120
  - app/views/expire_hosts_mailer/expiry_warning_notification.html.erb
@@ -132,6 +134,7 @@ files:
132
134
  - lib/foreman_expire_hosts/version.rb
133
135
  - lib/tasks/expired_hosts.rake
134
136
  - test/factories/foreman_expire_hosts_factories.rb
137
+ - test/functional/api/v2/hosts_controller_test.rb
135
138
  - test/functional/concerns/hosts_controller_extensions_test.rb
136
139
  - test/lib/expire_hosts_notifications_test.rb
137
140
  - test/test_plugin_helper.rb
@@ -160,12 +163,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
163
  version: '0'
161
164
  requirements: []
162
165
  rubyforge_project:
163
- rubygems_version: 2.6.12
166
+ rubygems_version: 2.7.3
164
167
  signing_key:
165
168
  specification_version: 4
166
169
  summary: Foreman plugin for limiting host lifetime
167
170
  test_files:
168
171
  - test/factories/foreman_expire_hosts_factories.rb
172
+ - test/functional/api/v2/hosts_controller_test.rb
169
173
  - test/functional/concerns/hosts_controller_extensions_test.rb
170
174
  - test/lib/expire_hosts_notifications_test.rb
171
175
  - test/test_plugin_helper.rb