diff --git a/app/controllers/epp/commands_controller.rb b/app/controllers/epp/commands_controller.rb index c8cb040d6..8e3c1ac19 100644 --- a/app/controllers/epp/commands_controller.rb +++ b/app/controllers/epp/commands_controller.rb @@ -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 diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 248acd103..1742f4b54 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -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 diff --git a/app/models/domain.rb b/app/models/domain.rb index 04c10b4b8..e36b68a05 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -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) diff --git a/app/views/epp/domains/renew.xml.builder b/app/views/epp/domains/renew.xml.builder new file mode 100644 index 000000000..34484b096 --- /dev/null +++ b/app/views/epp/domains/renew.xml.builder @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 7c417466c..e4ce7adda 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index bd05970e9..44229f0b6 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -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') diff --git a/spec/epp/requests/domains/renew.xml b/spec/epp/requests/domains/renew.xml new file mode 100644 index 000000000..1b8f89b0e --- /dev/null +++ b/spec/epp/requests/domains/renew.xml @@ -0,0 +1,14 @@ + + + + + + example.ee + 2000-04-03 + 1 + + + ABC-12345 + +