foreman_expire_hosts 6.0.1 → 7.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/controllers/concerns/foreman_expire_hosts/api/v2/hosts_controller_extensions.rb +2 -0
  4. data/app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb +20 -15
  5. data/app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb +2 -0
  6. data/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb +4 -22
  7. data/app/helpers/expire_hosts_mailer_helper.rb +2 -0
  8. data/app/helpers/foreman_expire_hosts/hosts_helper.rb +16 -0
  9. data/app/mailers/expire_hosts_mailer.rb +2 -0
  10. data/app/models/concerns/foreman_expire_hosts/host_ext.rb +3 -1
  11. data/app/models/host_status/expiration_status.rb +2 -0
  12. data/app/models/setting/expire_hosts.rb +2 -0
  13. data/app/overrides/add_expired_on_field_to_host_form.rb +2 -0
  14. data/app/overrides/add_expired_on_field_to_host_show.rb +2 -0
  15. data/app/overrides/deleted_expired_host_comment_in_audits.rb +2 -0
  16. data/app/services/foreman_expire_hosts/action/base.rb +5 -1
  17. data/app/services/foreman_expire_hosts/action/delete_expired_hosts.rb +3 -0
  18. data/app/services/foreman_expire_hosts/action/stop_expired_hosts.rb +3 -1
  19. data/app/services/foreman_expire_hosts/expiry_edit_authorizer.rb +2 -0
  20. data/app/services/foreman_expire_hosts/notification/base.rb +8 -3
  21. data/app/services/foreman_expire_hosts/notification/deleted_hosts.rb +2 -0
  22. data/app/services/foreman_expire_hosts/notification/expiry_warning.rb +2 -0
  23. data/app/services/foreman_expire_hosts/notification/failed_deleted_hosts.rb +2 -0
  24. data/app/services/foreman_expire_hosts/notification/failed_stopped_hosts.rb +2 -0
  25. data/app/services/foreman_expire_hosts/notification/stopped_hosts.rb +2 -0
  26. data/app/services/foreman_expire_hosts/safe_destroy.rb +7 -5
  27. data/app/services/foreman_expire_hosts/ui_notifications/hosts/base.rb +3 -1
  28. data/app/services/foreman_expire_hosts/ui_notifications/hosts/expiry_warning.rb +2 -0
  29. data/app/services/foreman_expire_hosts/ui_notifications/hosts/stopped_host.rb +2 -0
  30. data/app/views/api/v2/hosts/expiration.json.rabl +2 -0
  31. data/app/views/hosts/_expired_on_field.html.erb +11 -20
  32. data/app/views/hosts/select_multiple_expiration.html.erb +10 -15
  33. data/config/routes.rb +2 -0
  34. data/db/migrate/20150427101516_add_expiry_on_to_hosts.rb +2 -0
  35. data/db/seeds.d/80_expire_hosts_ui_notification.rb +2 -0
  36. data/extra/foreman_expire_hosts.cron +8 -0
  37. data/lib/expire_hosts_notifications.rb +2 -0
  38. data/lib/foreman_expire_hosts.rb +2 -0
  39. data/lib/foreman_expire_hosts/engine.rb +22 -10
  40. data/lib/foreman_expire_hosts/version.rb +3 -1
  41. data/lib/tasks/expired_hosts.rake +3 -1
  42. data/test/factories/foreman_expire_hosts_factories.rb +2 -0
  43. data/test/functional/api/v2/hosts_controller_test.rb +2 -0
  44. data/test/functional/concerns/hosts_controller_extensions_test.rb +3 -1
  45. data/test/helpers/hosts_helper_test.rb +5 -0
  46. data/test/lib/expire_hosts_notifications_test.rb +20 -1
  47. data/test/test_plugin_helper.rb +2 -0
  48. data/test/unit/concerns/host_extensions_test.rb +3 -1
  49. data/test/unit/expire_hosts_mailer_test.rb +6 -0
  50. data/test/unit/expiry_edit_authorizer_test.rb +2 -0
  51. data/test/unit/host_status/expiration_status_test.rb +2 -0
  52. data/test/unit/safe_destroy_test.rb +2 -0
  53. metadata +61 -42
  54. data/.gitignore +0 -15
  55. data/.rubocop.yml +0 -73
  56. data/.rubocop_todo.yml +0 -42
  57. data/Gemfile +0 -3
  58. data/app/assets/javascripts/foreman_expire_hosts/application.js +0 -3
  59. data/app/assets/javascripts/foreman_expire_hosts/datepicker_for_host_expired_on_field.js +0 -27
  60. data/app/assets/stylesheets/foreman_expire_hosts/application.scss +0 -4
  61. data/app/overrides/add_js_to_host_index.rb +0 -6
  62. data/foreman_expire_hosts.gemspec +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66c086d3dc04916321804be89e8d5f027691b5aa5dc10b0cef317b7ac5d4ee9e
4
- data.tar.gz: 84e16983231ab5651c03c5d56484c8645bd1c6910bd677aa7bcacefb139b06d2
3
+ metadata.gz: b5afc13d619d302e3e05ae902ff90f65d5eefd05e03b00369c7e3ca538260555
4
+ data.tar.gz: 9cdf5ad3a41cdc45a2fe0d4f5c0dc850e0a658abc72e20c83a436b5279a19268
5
5
  SHA512:
6
- metadata.gz: b2990701bc9efa238f25f6a6a7def12d87e9403e4b6cf0f41b477c1d5cc16a467f2edcb211fabd724034b3c149d00d654087a42e4a8e323fd403a2030ac81492
7
- data.tar.gz: 60a5e736f9e54223e5c62bcf426514e10aec9569708d3f58b672da60e41667b3537848c8fa6f00c8904c3c36aa87038304cdf44bc7d51e6a087d5c906ff3302d
6
+ metadata.gz: e65dddbebf6e2140e12fd05adf1b4584284c7e422a5399642eaf7e59e423b86561dbc9a7c0071835fbbffa50d3e34985ce31b1d1d3f955147e0849b2d8ea0d50
7
+ data.tar.gz: 4786bb290163e8f868dbe81d377d3747143cd5bcf3e00194625ea7f1c88f2ef0f6840fb2ccce7f5561a005140cacd6ea625a98b1b9fb45da4bf3444387a6047e
data/README.md CHANGED
@@ -18,6 +18,7 @@ This plugin will send two warning notifications before host expiry (see Settings
18
18
  | >= 1.16 | ~> 4.0 |
19
19
  | >= 1.17 | ~> 5.0 |
20
20
  | >= 1.18 | ~> 6.0 |
21
+ | >= 1.24 | ~> 7.0 |
21
22
 
22
23
  # Screenshots
23
24
  ![Expiry date field in host form](https://raw.githubusercontent.com/ingenico-group/screenshots/master/foreman_host_expiry/expiry-date-field-in-host-form.png)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Api
3
5
  module V2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module HostControllerExtensions
3
5
  def self.prepended(base)
@@ -11,23 +13,20 @@ module ForemanExpireHosts
11
13
  def select_multiple_expiration; end
12
14
 
13
15
  def update_multiple_expiration
14
- expiration_date = params[:host][:expired_on]
15
- expiration_date = Date.parse(expiration_date) if expiration_date.present?
16
-
17
16
  failed_hosts = {}
18
17
 
19
18
  @hosts.each do |host|
20
19
  begin
21
20
  host.expired_on = expiration_date
22
21
  host.save!
23
- rescue StandardError => error
24
- failed_hosts[host.name] = error
22
+ rescue StandardError => e
23
+ failed_hosts[host.name] = e
25
24
  message = if expiration_date.present?
26
25
  _('Failed to set expiration date for %{host} to %{expiration_date}.') % { :host => host, :expiration_date => l(expiration_date) }
27
26
  else
28
27
  _('Failed to clear expiration date for %s.') % host
29
28
  end
30
- Foreman::Logging.exception(message, error)
29
+ Foreman::Logging.exception(message, e)
31
30
  end
32
31
  end
33
32
 
@@ -48,15 +47,21 @@ module ForemanExpireHosts
48
47
  private
49
48
 
50
49
  def validate_multiple_expiration
51
- if params[:host].nil? || (expiration_date = params[:host][:expired_on]).nil?
52
- error _('No expiration date selected!')
53
- redirect_to(select_multiple_expiration_hosts_path) && (return false)
54
- end
55
- begin
56
- Date.parse(expiration_date) if expiration_date.present?
57
- rescue ArgumentError
58
- error _('Invalid expiration date!')
59
- redirect_to(select_multiple_expiration_hosts_path) && (return false)
50
+ expiration_date
51
+ rescue ArgumentError
52
+ error _('Invalid expiration date!')
53
+ redirect_to(hosts_path) && (return false)
54
+ end
55
+
56
+ def expiration_date
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}")
60
65
  end
61
66
  end
62
67
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module AuditsHelperExtensions
3
5
  extend ActiveSupport::Concern
@@ -1,19 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module HostsHelperExtensions
3
5
  extend ActiveSupport::Concern
4
6
 
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
15
- end
16
-
17
7
  def host_expiry_warning_message(host)
18
8
  return nil unless host.expires?
19
9
 
@@ -33,18 +23,10 @@ module ForemanExpireHosts
33
23
  distance_of_time_in_words(to_time, Time.current, options)
34
24
  end
35
25
 
36
- def input_group_addon(content, options = {})
37
- content_tag :span, class: 'input-group-addon' do
38
- content_tag :span, content, options
39
- end
40
- end
41
-
42
- def datepicker_f(form, attr, options = {})
26
+ def datepicker_f(form, attr, options = {}, html_options = {})
43
27
  field(form, attr, options) do
44
28
  addClass options, 'form-control'
45
- date = form.text_field attr, options
46
- addon = input_group_addon('', :class => 'glyphicon glyphicon-calendar')
47
- input_group date, addon
29
+ form.date_select(attr, options, html_options)
48
30
  end
49
31
  end
50
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExpireHostsMailerHelper
2
4
  def relative_date(date, opts = {})
3
5
  return _('N/A') if date.blank?
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanExpireHosts
4
+ module HostsHelper
5
+ def expire_hosts_host_multiple_actions
6
+ actions = []
7
+ if authorized_for(:controller => :hosts, :action => :select_multiple_expiration)
8
+ actions << {
9
+ action: [_('Change Expiration'), select_multiple_expiration_hosts_path],
10
+ priority: 200
11
+ }
12
+ end
13
+ actions
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ExpireHostsMailer < ApplicationMailer
2
4
  default :content_type => 'text/html', :from => Setting[:email_reply_address] || 'noreply@your-foreman.com'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module HostExt
3
5
  extend ActiveSupport::Concern
@@ -13,7 +15,7 @@ module ForemanExpireHosts
13
15
 
14
16
  scope :expiring, -> { where('expired_on IS NOT NULL') }
15
17
  scope :with_expire_date, ->(date) { expiring.where('expired_on = ?', date) }
16
- scope :expired, -> { expiring.where('expired_on < ?', Date.today) }
18
+ scope :expired, -> { expiring.where('expired_on <= ?', Date.today) }
17
19
  scope :expiring_today, -> { expiring.with_expire_date(Date.today) }
18
20
  scope :expired_past_grace_period, -> { expiring.where('expired_on <= ?', Date.today - Setting[:days_to_delete_after_host_expiration].to_i) }
19
21
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HostStatus
2
4
  class ExpirationStatus < HostStatus::Status
3
5
  OK = 0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Setting::ExpireHosts < Setting
2
4
  Setting::BLANK_ATTRS.push('host_expiry_email_recipients')
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Deface::Override.new(
2
4
  :virtual_path => 'hosts/_form',
3
5
  :name => 'host_form_expired_on_field',
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Deface::Override.new(
2
4
  :virtual_path => 'hosts/show',
3
5
  :name => 'host_expiry_waring_in_show',
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Deface::Override.new(
2
4
  :virtual_path => 'audits/_list',
3
5
  :name => 'deleted_expired_host_audit_comment_in_list',
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Action
3
5
  class Base
@@ -21,8 +23,10 @@ module ForemanExpireHosts
21
23
  next if result.nil?
22
24
 
23
25
  if result
26
+ logger.info "Action #{self.class.name} for host #{host.name} was successful."
24
27
  self.successful_hosts << host
25
28
  else
29
+ logger.info "Action #{self.class.name} for host #{host.name} failed."
26
30
  self.failed_hosts << host
27
31
  end
28
32
  end
@@ -54,7 +58,7 @@ module ForemanExpireHosts
54
58
  }
55
59
  end
56
60
 
57
- delegate :logger, :to => :Rails
61
+ delegate :logger, :to => :ForemanExpireHosts
58
62
  end
59
63
  end
60
64
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Action
3
5
  class DeleteExpiredHosts < Base
@@ -8,6 +10,7 @@ module ForemanExpireHosts
8
10
  end
9
11
 
10
12
  def action(host)
13
+ logger.info "Destroying expired host #{host}."
11
14
  SafeDestroy.new(host).destroy!
12
15
  end
13
16
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Action
3
5
  class StopExpiredHosts < Base
@@ -11,7 +13,7 @@ module ForemanExpireHosts
11
13
  return false unless host.supports_power?
12
14
  return unless host.power.ready?
13
15
 
14
- logger.info "Powering down expired host in grace period #{host}"
16
+ logger.info "Powering down expired host in grace period #{host}."
15
17
  host.power.stop
16
18
  rescue StandardError
17
19
  false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  class ExpiryEditAuthorizer
3
5
  attr_accessor :user, :hosts
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Notification
3
5
  class Base
@@ -26,22 +28,25 @@ module ForemanExpireHosts
26
28
  def deliver_mail_notification(recipient, hosts)
27
29
  return true if hosts.empty?
28
30
 
31
+ logger.info "Deliving mail notification '#{humanized_name}' for hosts #{hosts.to_sentence} to #{recipient}."
32
+
29
33
  build_mail_notification(recipient, hosts).deliver_now
30
- rescue SocketError, Net::SMTPError => error
34
+ rescue SocketError, Net::SMTPError => e
31
35
  message = _('Failed to deliver %{notification_name} for Hosts %{hosts}') % {
32
36
  :notification_name => humanized_name,
33
37
  :hosts => hosts.map(&:name).to_sentence
34
38
  }
35
- Foreman::Logging.exception(message, error)
39
+ Foreman::Logging.exception(message, e)
36
40
  end
37
41
 
38
42
  def deliver_ui_notifications
39
43
  all_hosts.each do |host|
44
+ logger.info "Deliving UI notification '#{humanized_name}' for host '#{host}'."
40
45
  build_ui_notification(host).deliver!
41
46
  end
42
47
  end
43
48
 
44
- delegate :logger, :to => :Rails
49
+ delegate :logger, :to => :ForemanExpireHosts
45
50
 
46
51
  def humanized_name
47
52
  _('Notification')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Notification
3
5
  class DeletedHosts < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Notification
3
5
  class ExpiryWarning < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Notification
3
5
  class FailedDeletedHosts < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Notification
3
5
  class FailedStoppedHosts < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module Notification
3
5
  class StoppedHosts < Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  class SafeDestroy
3
5
  # See http://projects.theforeman.org/issues/14702 for reasoning.
@@ -13,18 +15,18 @@ module ForemanExpireHosts
13
15
  # See https://community.theforeman.org/t/how-to-properly-destroy-a-content-host/8621
14
16
  # for reasoning.
15
17
  if subject.is_a?(Host::Base) && with_katello?
16
- Katello::RegistrationManager.unregister_host(host)
18
+ Katello::RegistrationManager.unregister_host(subject)
17
19
  else
18
20
  subject.destroy!
19
21
  end
20
- rescue ActiveRecord::RecordNotDestroyed => invalid
22
+ rescue ActiveRecord::RecordNotDestroyed => e
21
23
  message = _('Failed to delete %{class_name} %{subject}: %{message} - Errors: %{errors}') % {
22
24
  :class_name => subject.class.name,
23
25
  :subject => subject,
24
- :message => invalid.message,
25
- :errors => invalid.record.errors.full_messages.to_sentence
26
+ :message => e.message,
27
+ :errors => e.record.errors.full_messages.to_sentence
26
28
  }
27
- Foreman::Logging.exception(message, invalid)
29
+ Foreman::Logging.exception(message, e)
28
30
  false
29
31
  end
30
32
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module UINotifications
3
5
  module Hosts
@@ -46,7 +48,7 @@ module ForemanExpireHosts
46
48
 
47
49
  def redeliver!
48
50
  recipients = find_notification.notification_recipients
49
- recipients.update_all(seen: false) # rubocop:disable Rails/SkipsModelValidations
51
+ recipients.update_all(seen: false)
50
52
  recipients.pluck(:user_id).each do |user_id|
51
53
  ::UINotifications::CacheHandler.new(user_id).clear
52
54
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module UINotifications
3
5
  module Hosts
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
4
  module UINotifications
3
5
  module Hosts
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  attributes :expired_on
@@ -1,22 +1,13 @@
1
- <% if @host.can_modify_expiry_date? %>
2
- <%= stylesheet 'foreman_expire_hosts/application' %>
3
- <%= javascript 'foreman_expire_hosts/application' %>
4
- <% end %>
5
1
  <%= datepicker_f f, :expired_on,
6
- :value => @host.expired_on.try(:strftime, '%d/%m/%Y'),
7
- :data => { provide: @host.can_modify_expiry_date? ? 'datepicker' : 'readonly',
8
- orientation: 'top left',
9
- date_autoclose: true,
10
- date_clear_btn: true,
11
- date_format: 'dd/mm/yyyy',
12
- date_start_date: Date.tomorrow.strftime('%d/%m/%Y'),
13
- date_today_highlight: true
14
- },
15
- :autocomplete => false,
16
- :placeholder => 'dd/mm/yyyy',
17
- :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?),
18
- :readonly => !@host.can_modify_expiry_date?,
19
- :help_inline => popover('Auto Expiry', _('Host will be deleted automatically on given expiry date.') + '<br>'.html_safe +
20
- _('Leave blank to keep the host until deleted manually')),
21
- :onfocus => 'append_shortcuts()'
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
+ }
22
13
  %>
@@ -1,23 +1,18 @@
1
- <%= stylesheet 'foreman_expire_hosts/application' %>
2
- <%= javascript 'foreman_expire_hosts/application' %>
3
1
  <%= render 'selected_hosts', :hosts => @hosts %>
4
2
 
5
3
  <%= form_for :host, :url => update_multiple_expiration_hosts_path(:host_ids => params[:host_ids]) do |f| %>
6
4
 
7
- <%= _('Host will be deleted automatically on given expired date. Leave blank to clear expiration date.') %>
5
+ <%= _('Hosts will be deleted automatically on the given expiry date. Leave blank to clear expiration date.') %>
8
6
 
9
7
  <%= datepicker_f f, :expired_on,
10
- :value => (Date.today + 14).strftime('%d/%m/%Y'),
11
- :data => { provide: 'datepicker',
12
- orientation: 'top left',
13
- date_autoclose: true,
14
- date_clear_btn: true,
15
- date_format: 'dd/mm/yyyy',
16
- date_start_date: Date.tomorrow.strftime('%d/%m/%Y'),
17
- date_today_highlight: true
18
- },
19
- :autocomplete => false,
20
- :placeholder => 'dd/mm/yyyy',
21
- :onfocus => 'append_shortcuts()'
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
+ }
22
17
  %>
23
18
  <% end %>
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Foreman::Application.routes.draw do
2
4
  post 'expired_hosts/select_multiple_expiration' => 'hosts#select_multiple_expiration', as: 'select_multiple_expiration_hosts'
3
5
  post 'expired_hosts/update_multiple_expiration' => 'hosts#update_multiple_expiration', as: 'update_multiple_expiration_hosts'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddExpiryOnToHosts < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :hosts, :expired_on, :date unless column_exists? :hosts, :expired_on
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  [
2
4
  {
3
5
  group: _('Hosts'),
@@ -0,0 +1,8 @@
1
+ SHELL=/bin/sh
2
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
3
+
4
+ RAILS_ENV=production
5
+ FOREMAN_HOME=/usr/share/foreman
6
+
7
+ # Send out notifications about expired hosts
8
+ 45 7 * * * foreman /usr/sbin/foreman-rake expired_hosts:deliver_notifications >>/var/log/foreman/expired_hosts.log 2>&1
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ExpireHostsNotifications
2
4
  class << self
3
5
  def delete_expired_hosts
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_expire_hosts/engine'
2
4
  module ForemanExpireHosts
3
5
  end
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'deface'
2
- require 'bootstrap-datepicker-rails'
3
4
 
4
5
  module ForemanExpireHosts
5
6
  class Engine < ::Rails::Engine
@@ -24,7 +25,7 @@ module ForemanExpireHosts
24
25
 
25
26
  initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |_app|
26
27
  Foreman::Plugin.register :foreman_expire_hosts do
27
- requires_foreman '>= 1.18'
28
+ requires_foreman '>= 1.24'
28
29
  register_custom_status HostStatus::ExpirationStatus
29
30
 
30
31
  # strong parameters
@@ -34,22 +35,29 @@ module ForemanExpireHosts
34
35
  permission :edit_host_expiry,
35
36
  {},
36
37
  :resource_type => 'Host'
37
- permission :edit_hosts,
38
- { :hosts => [:select_multiple_expiration, :update_multiple_expiration] },
39
- :resource_type => 'Host'
40
38
  end
41
39
 
40
+ # Extend built in permissions
41
+ Foreman::AccessControl.permission(:edit_hosts).actions.concat [
42
+ 'hosts/select_multiple_expiration',
43
+ 'hosts/update_multiple_expiration'
44
+ ]
45
+
42
46
  extend_rabl_template 'api/v2/hosts/main', 'api/v2/hosts/expiration'
47
+
48
+ describe_host do
49
+ multiple_actions_provider :expire_hosts_host_multiple_actions
50
+ end
43
51
  end
44
52
  end
45
53
 
46
54
  config.to_prepare do
47
55
  begin
48
- Host::Managed.send :include, ForemanExpireHosts::HostExt
49
- HostsHelper.send :include, ForemanExpireHosts::HostsHelperExtensions
50
- HostsController.send :prepend, ForemanExpireHosts::HostControllerExtensions
51
- AuditsHelper.send :include, ForemanExpireHosts::AuditsHelperExtensions
52
- ::Api::V2::HostsController.send :include, ForemanExpireHosts::Api::V2::HostsControllerExtensions
56
+ ::Host::Managed.include ForemanExpireHosts::HostExt
57
+ ::HostsHelper.include ForemanExpireHosts::HostsHelperExtensions
58
+ ::HostsController.prepend ForemanExpireHosts::HostControllerExtensions
59
+ ::AuditsHelper.include ForemanExpireHosts::AuditsHelperExtensions
60
+ ::Api::V2::HostsController.include ForemanExpireHosts::Api::V2::HostsControllerExtensions
53
61
  rescue StandardError => e
54
62
  Rails.logger.warn "ForemanExpireHosts: skipping engine hook (#{e})"
55
63
  end
@@ -61,4 +69,8 @@ module ForemanExpireHosts
61
69
  end
62
70
  end
63
71
  end
72
+
73
+ def self.logger
74
+ Foreman::Logging.logger('foreman_expire_hosts')
75
+ end
64
76
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanExpireHosts
2
- VERSION = '6.0.1'.freeze
4
+ VERSION = '7.0.4'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Tasks
2
4
  namespace :expired_hosts do
3
5
  desc 'Delete all expired hosts, send notification email about expiring hosts'
@@ -24,7 +26,7 @@ namespace :test do
24
26
  end
25
27
 
26
28
  namespace :foreman_expire_hosts do
27
- task :rubocop do
29
+ task :rubocop => :environment do
28
30
  begin
29
31
  require 'rubocop/rake_task'
30
32
  RuboCop::RakeTask.new(:rubocop_foreman_expire_hosts) do |task|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.modify do
2
4
  factory :host do
3
5
  trait :without_validation do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class Api::V2::HostsControllerTest < ActionController::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class HostsControllerTest < ActionController::TestCase
@@ -68,7 +70,7 @@ class HostsControllerTest < ActionController::TestCase
68
70
  test 'should set expiration date' do
69
71
  expiration_date = Date.today + 14
70
72
  params = { :host_ids => @hosts.map(&:id),
71
- :host => { :expired_on => expiration_date } }
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 } }
72
74
 
73
75
  post :update_multiple_expiration, params: params, session: set_session_user.merge(:user => users(:admin).id)
74
76
 
@@ -1,7 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class HostsHelperTest < ActionView::TestCase
4
6
  include HostsHelper
7
+ include HostDescriptionHelper
8
+ include PuppetRelatedHelper
9
+ include ForemanExpireHosts::HostsHelper
5
10
  include ApplicationHelper
6
11
 
7
12
  describe '#multiple_actions' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
  require 'notifications_test_helper'
3
5
 
@@ -117,6 +119,23 @@ class ExpireHostsNotificationsTest < ActiveSupport::TestCase
117
119
  assert_equal 1, ActionMailer::Base.deliveries.count
118
120
  assert_includes ActionMailer::Base.deliveries.first.subject, 'Failed to stop expired hosts'
119
121
  end
122
+
123
+ context 'with a host expiring today' do
124
+ let(:host) { FactoryBot.create(:host, :expires_today, :on_compute_resource, :owner => user) }
125
+ let(:delete_date) { Date.today + Setting[:days_to_delete_after_host_expiration].to_i }
126
+
127
+ it 'should stop the host and show the correct delete date' do
128
+ power_mock.expects(:stop).returns(true)
129
+ ExpireHostsNotifications.stop_expired_hosts
130
+ assert_equal 1, ActionMailer::Base.deliveries.count
131
+ assert_includes ActionMailer::Base.deliveries.first.subject, 'Stopped expired hosts'
132
+ assert_includes ActionMailer::Base.deliveries.first.body, "These hosts will be destroyed on #{delete_date}."
133
+
134
+ travel_to delete_date do
135
+ assert_includes Host.expired_past_grace_period, host
136
+ end
137
+ end
138
+ end
120
139
  end
121
140
 
122
141
  context '#deliver_expiry_warning_notification' do
@@ -150,7 +169,7 @@ class ExpireHostsNotificationsTest < ActiveSupport::TestCase
150
169
  ExpireHostsNotifications.deliver_expiry_warning_notification
151
170
  notification = Notification.find_by(notification_blueprint_id: blueprint.id, subject_id: hosts.first.id)
152
171
  assert_not_nil notification
153
- assert_equal 1, NotificationRecipient.where(notification_id: notification.id).update_all(seen: true) # rubocop:disable Rails/SkipsModelValidations
172
+ assert_equal 1, NotificationRecipient.where(notification_id: notification.id).update_all(seen: true)
154
173
  ExpireHostsNotifications.deliver_expiry_warning_notification
155
174
  assert_equal 1, NotificationRecipient.where(notification_id: notification.id, seen: false).count
156
175
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
  require 'test_helper'
3
5
  require 'database_cleaner'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
@@ -180,7 +182,7 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
180
182
  end
181
183
 
182
184
  test 'should only exist in correct scopes' do
183
- exists_only_in_scopes(@host, ['expiring', 'expiring_today'])
185
+ exists_only_in_scopes(@host, ['expiring', 'expired', 'expiring_today'])
184
186
  end
185
187
  end
186
188
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class ExpireHostMailerTest < ActionMailer::TestCase
@@ -35,6 +37,10 @@ class ExpireHostMailerTest < ActionMailer::TestCase
35
37
  assert_includes mail.subject, 'Stopped expired hosts in Foreman'
36
38
  end
37
39
 
40
+ test 'should include a deletion date' do
41
+ assert_includes mail.body, "These hosts will be destroyed on #{Date.today}."
42
+ end
43
+
38
44
  test 'should show mitigation text if authorized' do
39
45
  ForemanExpireHosts::ExpiryEditAuthorizer.any_instance.stubs(:authorized?).returns(true)
40
46
  assert_includes mail.body.to_s, 'Please change their expiry date'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module ForemanExpireHosts
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class ExpirationStatusTest < ActiveSupport::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  module ForemanExpireHosts
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_expire_hosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 7.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagarjuna Rachaneni
8
8
  - Timo Goebel
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-01 00:00:00.000000000 Z
12
+ date: 2021-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bootstrap-datepicker-rails
15
+ name: deface
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
@@ -26,13 +26,13 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: deface
29
+ name: rdoc
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
- type: :runtime
35
+ type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
@@ -40,65 +40,85 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rdoc
43
+ name: rubocop
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: 0.80.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 0.80.0
56
56
  - !ruby/object:Gem::Dependency
57
- name: rubocop
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
58
86
  requirement: !ruby/object:Gem::Requirement
59
87
  requirements:
60
- - - '='
88
+ - - "~>"
61
89
  - !ruby/object:Gem::Version
62
- version: 0.59.2
90
+ version: 2.4.2
63
91
  type: :development
64
92
  prerelease: false
65
93
  version_requirements: !ruby/object:Gem::Requirement
66
94
  requirements:
67
- - - '='
95
+ - - "~>"
68
96
  - !ruby/object:Gem::Version
69
- version: 0.59.2
70
- description: This Plugin will add new column expired_on to hosts to limit the lifetime
71
- of a host.
97
+ version: 2.4.2
98
+ description: |
99
+ A Foreman plugin that allows hosts to expire at a configurable date.
100
+ Hosts will be shut down and automatically deleted after a grace period.
72
101
  email:
73
102
  - nn.nagarjuna@gmail.com
74
103
  - mail@timogoebel.name
75
104
  executables: []
76
105
  extensions: []
77
- extra_rdoc_files:
78
- - README.md
79
- - LICENSE
106
+ extra_rdoc_files: []
80
107
  files:
81
- - ".gitignore"
82
- - ".rubocop.yml"
83
- - ".rubocop_todo.yml"
84
- - Gemfile
85
108
  - LICENSE
86
109
  - README.md
87
- - app/assets/javascripts/foreman_expire_hosts/application.js
88
- - app/assets/javascripts/foreman_expire_hosts/datepicker_for_host_expired_on_field.js
89
- - app/assets/stylesheets/foreman_expire_hosts/application.scss
90
110
  - app/controllers/concerns/foreman_expire_hosts/api/v2/hosts_controller_extensions.rb
91
111
  - app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb
92
112
  - app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb
93
113
  - app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb
94
114
  - app/helpers/expire_hosts_mailer_helper.rb
115
+ - app/helpers/foreman_expire_hosts/hosts_helper.rb
95
116
  - app/mailers/expire_hosts_mailer.rb
96
117
  - app/models/concerns/foreman_expire_hosts/host_ext.rb
97
118
  - app/models/host_status/expiration_status.rb
98
119
  - app/models/setting/expire_hosts.rb
99
120
  - app/overrides/add_expired_on_field_to_host_form.rb
100
121
  - app/overrides/add_expired_on_field_to_host_show.rb
101
- - app/overrides/add_js_to_host_index.rb
102
122
  - app/overrides/deleted_expired_host_comment_in_audits.rb
103
123
  - app/services/foreman_expire_hosts/action/base.rb
104
124
  - app/services/foreman_expire_hosts/action/delete_expired_hosts.rb
@@ -127,7 +147,7 @@ files:
127
147
  - config/routes.rb
128
148
  - db/migrate/20150427101516_add_expiry_on_to_hosts.rb
129
149
  - db/seeds.d/80_expire_hosts_ui_notification.rb
130
- - foreman_expire_hosts.gemspec
150
+ - extra/foreman_expire_hosts.cron
131
151
  - lib/expire_hosts_notifications.rb
132
152
  - lib/foreman_expire_hosts.rb
133
153
  - lib/foreman_expire_hosts/engine.rb
@@ -148,7 +168,7 @@ homepage: https://github.com/theforeman/foreman_expire_hosts
148
168
  licenses:
149
169
  - GPL-3.0
150
170
  metadata: {}
151
- post_install_message:
171
+ post_install_message:
152
172
  rdoc_options: []
153
173
  require_paths:
154
174
  - lib
@@ -163,20 +183,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
183
  - !ruby/object:Gem::Version
164
184
  version: '0'
165
185
  requirements: []
166
- rubyforge_project:
167
- rubygems_version: 2.7.6.2
168
- signing_key:
186
+ rubygems_version: 3.1.2
187
+ signing_key:
169
188
  specification_version: 4
170
189
  summary: Foreman plugin for limiting host lifetime
171
190
  test_files:
172
- - test/factories/foreman_expire_hosts_factories.rb
173
- - test/functional/api/v2/hosts_controller_test.rb
174
- - test/functional/concerns/hosts_controller_extensions_test.rb
175
- - test/helpers/hosts_helper_test.rb
176
- - test/lib/expire_hosts_notifications_test.rb
177
- - test/test_plugin_helper.rb
178
- - test/unit/concerns/host_extensions_test.rb
179
191
  - test/unit/expire_hosts_mailer_test.rb
180
- - test/unit/expiry_edit_authorizer_test.rb
181
192
  - test/unit/host_status/expiration_status_test.rb
182
193
  - test/unit/safe_destroy_test.rb
194
+ - test/unit/expiry_edit_authorizer_test.rb
195
+ - test/unit/concerns/host_extensions_test.rb
196
+ - test/factories/foreman_expire_hosts_factories.rb
197
+ - test/lib/expire_hosts_notifications_test.rb
198
+ - test/test_plugin_helper.rb
199
+ - test/helpers/hosts_helper_test.rb
200
+ - test/functional/api/v2/hosts_controller_test.rb
201
+ - test/functional/concerns/hosts_controller_extensions_test.rb
data/.gitignore DELETED
@@ -1,15 +0,0 @@
1
- *.sw?
2
- .idea
3
- .bundle/
4
- log/*.log
5
- pkg/
6
- test/dummy/db/*.sqlite3
7
- test/dummy/log/*.log
8
- test/dummy/tmp/
9
- test/dummy/.sass-cache
10
- locale/*.mo
11
- locale/*/*.pox
12
- locale/*/*.edit.po
13
- locale/*/*.po.time_stamp
14
- Gemfile.lock
15
- *.gem
data/.rubocop.yml DELETED
@@ -1,73 +0,0 @@
1
- inherit_from:
2
- - .rubocop_todo.yml
3
-
4
- AllCops:
5
- TargetRubyVersion: 2.2
6
- TargetRailsVersion: 5.1
7
- Exclude:
8
- - 'Rakefile'
9
-
10
- Rails:
11
- Enabled: true
12
-
13
- Rails/Date:
14
- Enabled: false
15
-
16
- # Don't enforce documentation
17
- Style/Documentation:
18
- Enabled: false
19
-
20
- Metrics/MethodLength:
21
- Max: 40
22
-
23
- Naming/AccessorMethodName:
24
- Enabled: false
25
-
26
- Style/RedundantSelf:
27
- Enabled: false
28
-
29
- Metrics/ClassLength:
30
- Max: 500
31
-
32
- Naming/FileName:
33
- Exclude:
34
- - 'db/seeds.d/*'
35
-
36
- Style/WordArray:
37
- Enabled: false
38
-
39
- Style/BracesAroundHashParameters:
40
- Enabled: false
41
-
42
- Style/RescueModifier:
43
- Enabled: false
44
-
45
- Style/ClassAndModuleChildren:
46
- Enabled: false
47
-
48
- Style/EachWithObject:
49
- Enabled: false
50
-
51
- Metrics/ParameterLists:
52
- Enabled: false
53
-
54
- Style/SymbolArray:
55
- Enabled: false
56
-
57
- Style/FormatString:
58
- Enabled: false
59
-
60
- Style/FormatStringToken:
61
- Enabled: false
62
-
63
- Style/HashSyntax:
64
- Enabled: false
65
-
66
- Rails/HasManyOrHasOneDependent:
67
- Enabled: false
68
-
69
- Style/CommentedKeyword:
70
- Enabled: false
71
-
72
- Rails/LexicallyScopedActionFilter:
73
- Enabled: false
data/.rubocop_todo.yml DELETED
@@ -1,42 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2017-08-01 16:36:14 +0200 using RuboCop version 0.49.1.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 12
10
- Metrics/AbcSize:
11
- Max: 51
12
-
13
- # Offense count: 4
14
- # Configuration parameters: CountComments, ExcludedMethods.
15
- Metrics/BlockLength:
16
- Max: 35
17
- Exclude:
18
- - 'test/**/*.rb'
19
-
20
- # Offense count: 3
21
- Metrics/CyclomaticComplexity:
22
- Max: 11
23
-
24
- # Offense count: 89
25
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
26
- # URISchemes: http, https
27
- Metrics/LineLength:
28
- Max: 362
29
-
30
- # Offense count: 1
31
- # Configuration parameters: CountComments.
32
- Metrics/ModuleLength:
33
- Max: 110
34
-
35
- # Offense count: 3
36
- Metrics/PerceivedComplexity:
37
- Max: 11
38
-
39
- # Offense count: 2
40
- Rails/OutputSafety:
41
- Exclude:
42
- - 'app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb'
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec
@@ -1,3 +0,0 @@
1
- //= require bootstrap-datepicker
2
- //= require foreman_expire_hosts/datepicker_for_host_expired_on_field
3
-
@@ -1,27 +0,0 @@
1
- var shortcuts = {"1 day": 1, "1 week": 7, "1 month": 30, "1 year": 365, "3 days": 3, "3 weeks": 21, "3 months": 90};
2
- function append_shortcuts() {
3
- if ($(".datepicker-days #datepicker_shortcuts").length == 0) {
4
- var shortcuts_html = "<div id='datepicker_shortcuts'><div>";
5
- var shortcut_item = 1;
6
- $.each(shortcuts, function (lable, days) {
7
- var today = new Date();
8
- today.setDate(today.getDate() + days);
9
- if (shortcut_item == 5) {
10
- shortcuts_html += "</div><div style='padding-top: 3px'>"
11
- }
12
- shortcuts_html += "<a style='width: 65px;' class='btn btn-default btn-xs' role='button' title='" + $.fn.datepicker.dates.en.monthsShort[today.getMonth()] + " " + today.getDate() + " " + today.getFullYear() + "' onclick='populate_date_from_days(" + days + ")'>" + lable + "</a>&nbsp;";
13
- shortcut_item += 1
14
- });
15
- shortcuts_html += "</div></div>";
16
- $(".datepicker-days table").before(shortcuts_html)
17
- }
18
- }
19
-
20
- function populate_date_from_days(shortcut_days) {
21
- var today = new Date();
22
- today.setDate(today.getDate() + shortcut_days);
23
- $('#host_expired_on').datepicker('setDate', today);
24
- $('#host_expired_on').datepicker('remove');
25
- //$('#host_expired_on').val(today.getDate()+'/'+(today.getMonth()+1)+'/'+today.getFullYear())
26
- //$('#host_expired_on').datepicker('hide')
27
- }
@@ -1,4 +0,0 @@
1
- /*
2
- *= require_self
3
- *= require bootstrap-datepicker3
4
- */
@@ -1,6 +0,0 @@
1
- Deface::Override.new(
2
- :virtual_path => 'hosts/_list',
3
- :name => 'host_list_expiration_js',
4
- :insert_before => '#confirmation-modal',
5
- :text => "<%= stylesheet 'foreman_expire_hosts/application' %><%= javascript 'foreman_expire_hosts/application' %>"
6
- )
@@ -1,26 +0,0 @@
1
- require File.expand_path('lib/foreman_expire_hosts/version', __dir__)
2
- require 'date'
3
-
4
- Gem::Specification.new do |s|
5
- s.name = 'foreman_expire_hosts'
6
- s.version = ForemanExpireHosts::VERSION
7
- s.date = Date.today.to_s
8
- s.authors = ['Nagarjuna Rachaneni', 'Timo Goebel']
9
- s.email = ['nn.nagarjuna@gmail.com', 'mail@timogoebel.name']
10
- s.summary = 'Foreman plugin for limiting host lifetime'
11
- s.description = 'This Plugin will add new column expired_on to hosts to limit the lifetime of a host.'
12
- s.homepage = 'https://github.com/theforeman/foreman_expire_hosts'
13
- s.licenses = ['GPL-3.0']
14
-
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files test`.split("\n")
17
- s.extra_rdoc_files = `git ls-files doc`.split("\n") + Dir['README*', 'LICENSE']
18
-
19
- s.require_paths = ['lib']
20
-
21
- s.add_dependency 'bootstrap-datepicker-rails'
22
- s.add_dependency 'deface'
23
-
24
- s.add_development_dependency 'rdoc'
25
- s.add_development_dependency 'rubocop', '0.59.2'
26
- end