Refactor EppDomain to Epp::Domain

This commit is contained in:
Martin Lensment 2015-03-10 14:55:45 +02:00
parent 2c35617745
commit d558b2eed9
7 changed files with 19 additions and 49 deletions

View file

@ -5,8 +5,8 @@ class Epp::DomainsController < EppController
before_action :find_password, only: [:info, :update, :transfer, :delete] before_action :find_password, only: [:info, :update, :transfer, :delete]
def create def create
authorize! :create, Epp::EppDomain authorize! :create, Epp::Domain
@domain = Epp::EppDomain.new_from_epp(params[:parsed_frame], current_user) @domain = Epp::Domain.new_from_epp(params[:parsed_frame], current_user)
if @domain.errors.any? || !@domain.save if @domain.errors.any? || !@domain.save
handle_errors(@domain) handle_errors(@domain)
@ -21,15 +21,15 @@ class Epp::DomainsController < EppController
end end
def check def check
authorize! :check, Epp::EppDomain authorize! :check, Epp::Domain
names = params[:parsed_frame].css('name').map(&:text) names = params[:parsed_frame].css('name').map(&:text)
@domains = Epp::EppDomain.check_availability(names) @domains = Epp::Domain.check_availability(names)
render_epp_response '/epp/domains/check' render_epp_response '/epp/domains/check'
end end
def renew def renew
authorize! :renew, Epp::EppDomain authorize! :renew, Epp::Domain
handle_errors(@domain) and return unless @domain.renew( handle_errors(@domain) and return unless @domain.renew(
params[:parsed_frame].css('curExpDate').text, params[:parsed_frame].css('curExpDate').text,
@ -92,7 +92,7 @@ class Epp::DomainsController < EppController
def delete def delete
handle_errors(@domain) and return unless @domain.can_be_deleted? handle_errors(@domain) and return unless @domain.can_be_deleted?
@domain.attach_legal_document(Epp::EppDomain.parse_legal_document_from_frame(params[:parsed_frame])) @domain.attach_legal_document(Epp::Domain.parse_legal_document_from_frame(params[:parsed_frame]))
@domain.save(validate: false) @domain.save(validate: false)
handle_errors(@domain) and return unless @domain.destroy handle_errors(@domain) and return unless @domain.destroy
@ -169,7 +169,7 @@ class Epp::DomainsController < EppController
def find_domain def find_domain
domain_name = params[:parsed_frame].css('name').text.strip.downcase domain_name = params[:parsed_frame].css('name').text.strip.downcase
@domain = Epp::EppDomain.find_by(name: domain_name) @domain = Epp::Domain.find_by(name: domain_name)
unless @domain unless @domain
epp_errors << { epp_errors << {

View file

@ -34,7 +34,7 @@ class Epp::KeyrelaysController < EppController
def find_domain def find_domain
domain_name = params[:parsed_frame].css('name').text.strip.downcase domain_name = params[:parsed_frame].css('name').text.strip.downcase
domain = Epp::EppDomain.includes(:owner_contact).find_by(name: domain_name) domain = Epp::Domain.includes(:owner_contact).find_by(name: domain_name)
unless domain unless domain
epp_errors << { epp_errors << {

View file

@ -27,12 +27,12 @@ class Ability
can(:view_password, Epp::Contact) { |c| c.registrar_id == @user.registrar_id } can(:view_password, Epp::Contact) { |c| c.registrar_id == @user.registrar_id }
# Epp::Domain # Epp::Domain
can(:info, Epp::EppDomain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw } can(:info, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw }
can(:check, Epp::EppDomain) can(:check, Epp::Domain)
can(:create, Epp::EppDomain) can(:create, Epp::Domain)
can(:renew, Epp::EppDomain) can(:renew, Epp::Domain)
can(:update, Epp::EppDomain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw } can(:update, Epp::Domain) { |d, pw| d.registrar_id == @user.registrar_id || d.auth_info == pw }
can(:transfer, Epp::EppDomain) { |d, pw| d.auth_info == pw } can(:transfer, Epp::Domain) { |d, pw| d.auth_info == pw }
end end
def user def user

View file

@ -1,5 +1,5 @@
# rubocop: disable Metrics/ClassLength # rubocop: disable Metrics/ClassLength
class Epp::EppDomain < Domain class Epp::Domain < Domain
include EppErrors include EppErrors
def epp_code_map # rubocop:disable Metrics/MethodLength def epp_code_map # rubocop:disable Metrics/MethodLength
@ -59,7 +59,7 @@ class Epp::EppDomain < Domain
end end
def self.new_from_epp(frame, current_user) def self.new_from_epp(frame, current_user)
domain = Epp::EppDomain.new domain = Epp::Domain.new
domain.attributes = domain.attrs_from(frame, current_user) domain.attributes = domain.attrs_from(frame, current_user)
domain.attach_default_contacts domain.attach_default_contacts
domain domain
@ -105,7 +105,7 @@ class Epp::EppDomain < Domain
period = frame.css('period').text period = frame.css('period').text
at[:period] = (period.to_i == 0) ? 1 : period.to_i at[:period] = (period.to_i == 0) ? 1 : period.to_i
at[:period_unit] = Epp::EppDomain.parse_period_unit_from_frame(frame) || 'y' at[:period_unit] = Epp::Domain.parse_period_unit_from_frame(frame) || 'y'
at[:nameservers_attributes] = nameservers_attrs(frame, action) at[:nameservers_attributes] = nameservers_attrs(frame, action)
at[:domain_contacts_attributes] = domain_contacts_attrs(frame, action) at[:domain_contacts_attributes] = domain_contacts_attrs(frame, action)

View file

@ -1,30 +0,0 @@
module EppParser
def domain_rem_params
{
nameservers_attributes: to_destroy
}
end
def nameservers_attributes
ns_list = Epp::EppDomain.parse_nameservers_from_frame(params[:parsed_frame])
to_destroy = []
ns_list.each do |ns_attrs|
nameserver = @domain.nameservers.where(ns_attrs).try(:first)
if nameserver.blank?
epp_errors << {
code: '2303',
msg: I18n.t('nameserver_not_found'),
value: { obj: 'hostAttr', val: ns_attrs[:hostname] }
}
else
to_destroy << {
id: nameserver.id,
_destroy: 1
}
end
end
end
end

View file

@ -1 +1 @@
Fabricator(:epp_domain, from: :domain, class_name: 'Epp::EppDomain') Fabricator(:epp_domain, from: :domain, class_name: 'Epp::Domain')

View file

@ -1,6 +1,6 @@
require 'rails_helper' require 'rails_helper'
describe Epp::EppDomain do describe Epp::Domain do
context 'with sufficient settings' do context 'with sufficient settings' do
let(:domain) { Fabricate(:epp_domain) } let(:domain) { Fabricate(:epp_domain) }