mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Add ISO 8601 validations
This commit is contained in:
parent
b5bf21b127
commit
2ac59e68ff
10 changed files with 104 additions and 4 deletions
|
@ -357,7 +357,7 @@ class Epp::EppDomain < Domain
|
|||
end
|
||||
|
||||
abs_datetime = parsed_frame.css('absolute').text
|
||||
abs_datetime = abs_datetime.to_date if abs_datetime
|
||||
abs_datetime = DateTime.parse(abs_datetime) if abs_datetime.present?
|
||||
|
||||
transaction do
|
||||
kr = keyrelays.create(
|
||||
|
@ -373,14 +373,16 @@ class Epp::EppDomain < Domain
|
|||
accepter: registrar
|
||||
)
|
||||
|
||||
registrar.messages.create(
|
||||
return false unless valid?
|
||||
|
||||
registrar.messages.create!(
|
||||
body: 'Key Relay action completed successfully.',
|
||||
attached_obj_type: kr.class.to_s,
|
||||
attached_obj_id: kr.id
|
||||
)
|
||||
|
||||
kr
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
### VALIDATIONS ###
|
||||
|
|
|
@ -1,8 +1,34 @@
|
|||
class Keyrelay < ActiveRecord::Base
|
||||
include EppErrors
|
||||
|
||||
belongs_to :domain
|
||||
|
||||
belongs_to :requester, class_name: 'Registrar'
|
||||
belongs_to :accepter, class_name: 'Registrar'
|
||||
|
||||
delegate :name, to: :domain, prefix: true
|
||||
|
||||
validates :expiry_relative, duration_iso8601: true
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2005' => [
|
||||
[:expiry_relative, :unknown_pattern, { value: { obj: 'relative', val: expiry_relative } }]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def status
|
||||
if expiry_relative
|
||||
exp_date = pa_date + ISO8601::Duration.new(expiry_relative).to_seconds
|
||||
elsif expiry_absolute
|
||||
exp_date = expiry_positive
|
||||
end
|
||||
|
||||
if Time.now > exp_date
|
||||
return 'expired'
|
||||
else
|
||||
return 'pending'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,8 @@ class Message < ActiveRecord::Base
|
|||
|
||||
scope :queued, -> { where(queued: true) }
|
||||
|
||||
validates :body, presence: true
|
||||
|
||||
def dequeue
|
||||
self.queued = false
|
||||
save
|
||||
|
|
9
app/validators/duration_iso8601_validator.rb
Normal file
9
app/validators/duration_iso8601_validator.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class DurationIso8601Validator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
return unless value.present?
|
||||
|
||||
ISO8601::Duration.new(value)
|
||||
rescue => _e
|
||||
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :unknown_pattern))
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue