Module: ForemanExpireHosts::HostExt

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/foreman_expire_hosts/host_ext.rb

Instance Method Summary collapse

Instance Method Details

#can_modify_expiry_date?Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/concerns/foreman_expire_hosts/host_ext.rb', line 74

def can_modify_expiry_date?
  return true if new_record?
  return true if defined?(Rails::Console)
  return true unless User.current
  return true if Authorizer.new(User.current).can?(:edit_host_expiry, self)
  return true if self.owner_type.nil? || self.owner.nil?

  Setting[:can_owner_modify_host_expiry_date] &&
    ((self.owner_type == 'User' && self.owner == User.current) ||
     (self.owner_type == 'Usergroup' && self.owner.all_users.include?(User.current)))
end

#expiration_grace_period_end_dateObject



55
56
57
58
59
# File 'app/models/concerns/foreman_expire_hosts/host_ext.rb', line 55

def expiration_grace_period_end_date
  return nil unless expires?

  expired_on.to_date + Setting[:days_to_delete_after_host_expiration].to_i.days
end

#expired?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'app/models/concerns/foreman_expire_hosts/host_ext.rb', line 49

def expired?
  return false unless expires?

  expired_on.to_date < Date.today
end

#expired_past_grace_period?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
# File 'app/models/concerns/foreman_expire_hosts/host_ext.rb', line 61

def expired_past_grace_period?
  return false unless expires?

  expiration_grace_period_end_date.to_date <= Date.today
end

#expires?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/concerns/foreman_expire_hosts/host_ext.rb', line 39

def expires?
  expired_on.present?
end

#expires_today?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'app/models/concerns/foreman_expire_hosts/host_ext.rb', line 43

def expires_today?
  return false unless expires?

  expired_on.to_date == Date.today
end

#pending_expiration?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
# File 'app/models/concerns/foreman_expire_hosts/host_ext.rb', line 67

def pending_expiration?
  return false unless expires?
  return false if expired?

  expired_on.to_date - Setting['notify1_days_before_host_expiry'].to_i.days <= Date.today
end

#validate_expired_onObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/concerns/foreman_expire_hosts/host_ext.rb', line 25

def validate_expired_on
  if self.expires?
    begin
      errors.add(:expired_on, _('must be in the future')) unless expired_on.to_s.to_date > Date.today
    rescue StandardError
      errors.add(:expired_on, _('is invalid'))
    end
  end
  if self.changed.include?('expired_on')
    errors.add(:expired_on, _('no permission to edit')) unless can_modify_expiry_date?
  end
  true
end