Handle OK status automatically

This commit is contained in:
Martin Lensment 2014-09-29 15:54:02 +03:00
parent 8892a25947
commit 77510cc3fa
5 changed files with 19 additions and 10 deletions

View file

@ -36,6 +36,7 @@ class Domain < ActiveRecord::Base
before_create :generate_auth_info
before_create :set_validity_dates
after_create :attach_default_contacts
after_save :manage_automatic_statuses
validates :name_dirty, domain_name: true, uniqueness: true
validates :period, numericality: { only_integer: true }
@ -201,6 +202,14 @@ class Domain < ActiveRecord::Base
domain_contacts.reject(&:marked_for_destruction?).select { |x| x.contact_type == DomainContact::ADMIN }.count
end
def manage_automatic_statuses
if domain_statuses.empty? && valid?
domain_statuses.create(value: DomainStatus::OK)
else
domain_statuses.find_by(value: DomainStatus::OK).try(:destroy)
end
end
class << self
def convert_period_to_time(period, unit)
return period.to_i.days if unit == 'd'