Delete and transfer to cancan

This commit is contained in:
Martin Lensment 2015-03-10 12:40:25 +02:00
parent 8a8da67d38
commit 010cc81e10
4 changed files with 11 additions and 71 deletions

View file

@ -1,8 +1,8 @@
class Epp::DomainsController < EppController
skip_authorization_check # TODO: remove it
before_action :find_domain, only: [:info, :renew, :update]
before_action :find_password, only: [:info, :update]
before_action :find_domain, only: [:info, :renew, :update, :transfer, :delete]
before_action :find_password, only: [:info, :update, :transfer, :delete]
def create
authorize! :create, Epp::EppDomain
@ -55,9 +55,7 @@ class Epp::DomainsController < EppController
# rubocop: disable Metrics/MethodLength
def transfer
@domain = find_domain
handle_errors(@domain) and return unless @domain
handle_errors(@domain) and return unless @domain.authenticate(domain_transfer_params[:pw])
authorize! :transfer, @domain, @password
if domain_transfer_params[:action] == 'query'
if @domain.pending_transfer
@ -92,9 +90,6 @@ class Epp::DomainsController < EppController
# rubocop:disable Metrics/CyclomaticComplexity
def delete
@domain = find_domain
handle_errors(@domain) and return unless @domain
handle_errors(@domain) and return unless @domain.can_be_deleted?
@domain.attach_legal_document(Epp::EppDomain.parse_legal_document_from_frame(params[:parsed_frame]))
@ -164,31 +159,6 @@ class Epp::DomainsController < EppController
requires 'name'
end
def domain_rem_params
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
{
nameservers_attributes: to_destroy
}
end
def domain_transfer_params
res = {}
res[:pw] = params[:parsed_frame].css('pw').first.try(:text)
@ -217,17 +187,3 @@ class Epp::DomainsController < EppController
@password = params[:parsed_frame].css('authInfo pw').text
end
end
# return domain if domain.auth_info == params[:parsed_frame].css('authInfo pw').text
# if (domain.registrar != current_user.registrar) && secure[:secure] == true
# epp_errors << {
# code: '2302',
# msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'),
# value: { obj: 'name', val: params[:parsed_frame].css('name').text.strip.downcase }
# }
# return nil
# end
# domain

View file

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

View file

@ -11,9 +11,6 @@ class Nameserver < ActiveRecord::Base
validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
# rubocop: enable Metrics/LineLength
# TODO: remove old
# after_destroy :domain_version
before_validation :normalize_attributes
delegate :name, to: :domain, prefix: true
@ -34,26 +31,12 @@ class Nameserver < ActiveRecord::Base
}
end
# TODO: remove old
# def snapshot
# {
# hostname: hostname,
# ipv4: ipv4,
# ipv6: ipv6
# }
# end
def normalize_attributes
self.hostname = hostname.try(:strip).try(:downcase)
self.ipv4 = ipv4.try(:strip)
self.ipv6 = ipv6.try(:strip).try(:upcase)
end
# TODO: remove old
# def domain_version
# domain.create_version if domain
# end
def to_s
hostname
end

View file

@ -984,7 +984,7 @@ describe 'EPP Domain', epp: true do
response = epp_plain_request(xml, :xml)
response[:result_code].should == '2201'
response[:msg].should == 'Authorization error [auth_info]'
response[:msg].should == 'Authorization error'
end
it 'ignores transfer when owner registrar requests transfer' do
@ -1031,7 +1031,7 @@ describe 'EPP Domain', epp: true do
epp_plain_request(xml, :xml) # transfer domain
response = epp_plain_request(xml, :xml) # attempt second transfer
response[:result_code].should == '2201'
response[:msg].should == 'Authorization error [auth_info]'
response[:msg].should == 'Authorization error'
end
end