mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Basic domain renew
This commit is contained in:
parent
d62106da20
commit
b828645920
7 changed files with 69 additions and 0 deletions
|
@ -9,6 +9,10 @@ class Epp::CommandsController < ApplicationController
|
|||
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||
end
|
||||
|
||||
def renew
|
||||
send("renew_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||
end
|
||||
|
||||
def check
|
||||
send("check_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||
end
|
||||
|
|
|
@ -19,6 +19,23 @@ module Epp::DomainsHelper
|
|||
render '/epp/domains/check'
|
||||
end
|
||||
|
||||
def renew_domain
|
||||
ph = params_hash['epp']['command']['renew']['renew']
|
||||
|
||||
@domain = Domain.find_by(name: ph[:name])
|
||||
unless @domain
|
||||
epp_errors << {code: '2303', msg: I18n.t('errors.messages.epp_domain_not_found'), value: {obj: 'domain', val: ph[:name]}}
|
||||
render '/epp/error' and return
|
||||
end
|
||||
|
||||
if @domain.renew(ph[:curExpDate], ph[:period])
|
||||
render '/epp/domains/renew'
|
||||
else
|
||||
handle_errors
|
||||
render '/epp/error'
|
||||
end
|
||||
end
|
||||
|
||||
### HELPER METHODS ###
|
||||
private
|
||||
|
||||
|
|
|
@ -124,6 +124,16 @@ class Domain < ActiveRecord::Base
|
|||
errors.add(:admin_contacts, :blank) if admin_contacts.empty?
|
||||
end
|
||||
|
||||
def renew(cur_exp_date, period, unit='y')
|
||||
if cur_exp_date == valid_to
|
||||
valid_to = period.to_i.years
|
||||
else
|
||||
errors[:base] << {msg: I18n.t('errors.messages.epp_exp_dates_do_not_match'), obj: 'domain', val: cur_exp_date}
|
||||
end
|
||||
|
||||
save
|
||||
end
|
||||
|
||||
class << self
|
||||
def check_availability(domains)
|
||||
domains = [domains] if domains.is_a?(String)
|
||||
|
|
16
app/views/epp/domains/renew.xml.builder
Normal file
16
app/views/epp/domains/renew.xml.builder
Normal file
|
@ -0,0 +1,16 @@
|
|||
xml.epp_head do
|
||||
xml.response do
|
||||
xml.result('code' => '1000') do
|
||||
xml.msg 'Command completed successfully'
|
||||
end
|
||||
|
||||
xml.resData do
|
||||
xml.tag!('domain:renData', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
||||
xml.tag!('domain:name', @domain[:name])
|
||||
xml.tag!('domain:exDate', @domain.valid_to)
|
||||
end
|
||||
end
|
||||
|
||||
xml << render('/epp/shared/trID')
|
||||
end
|
||||
end
|
|
@ -71,3 +71,5 @@ en:
|
|||
epp_command_failed: 'Command failed'
|
||||
epp_authorization_error: 'Authorization error'
|
||||
epp_id_taken: 'Contact id already exists'
|
||||
epp_domain_not_found: 'Domain not found'
|
||||
epp_exp_dates_do_not_match: 'Given and current expire dates do not match'
|
||||
|
|
|
@ -131,6 +131,12 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with valid domain' do
|
||||
before(:each) { Fabricate(:domain, name: 'example.ee') }
|
||||
|
||||
|
||||
end
|
||||
|
||||
it 'checks a domain' do
|
||||
response = epp_request('domains/check.xml')
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
|
|
14
spec/epp/requests/domains/renew.xml
Normal file
14
spec/epp/requests/domains/renew.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<renew>
|
||||
<domain:renew
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:curExpDate>2000-04-03</domain:curExpDate>
|
||||
<domain:period unit="y">1</domain:period>
|
||||
</domain:renew>
|
||||
</renew>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
Loading…
Add table
Add a link
Reference in a new issue