Allow ident data modification on EPP contact:update

#569
This commit is contained in:
Artur Beljajev 2017-07-22 22:53:52 +03:00
parent 06e080ed43
commit ba53a3e323
3 changed files with 60 additions and 28 deletions

View file

@ -148,7 +148,6 @@ class Epp::Contact < Contact
}
end
# rubocop:disable Metrics/AbcSize
def update_attributes(frame, current_user)
return super if frame.blank?
at = {}.with_indifferent_access
@ -158,9 +157,6 @@ class Epp::Contact < Contact
at[:statuses] = statuses - statuses_attrs(frame.css('rem'), 'rem') + statuses_attrs(frame.css('add'), 'add')
end
# legal_frame = frame.css('legalDocument').first
# at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
self.legal_document_id = doc.id
@ -168,28 +164,31 @@ class Epp::Contact < Contact
self.deliver_emails = true # turn on email delivery for epp
# allow to update ident code for legacy contacts
# Allow ident data update for legacy contacts
if frame.css('ident').first
self.ident_updated_at ||= Time.zone.now
ident_frame = frame.css('ident').first
if ident_frame.text.present?
deny_ident_update
end
if ident_frame && ident_attr_valid?(ident_frame)
org_priv = %w(org priv).freeze
if ident_country_code.blank? && org_priv.include?(ident_type) && org_priv.include?(ident_frame.attr('type'))
at.merge!(ident_country_code: ident_frame.attr('cc'), ident_type: ident_frame.attr('type'))
elsif ident_type == "birthday" && !ident[/\A\d{4}-\d{2}-\d{2}\z/] && (Date.parse(ident) rescue false)
at.merge!(ident: ident_frame.text)
at.merge!(ident_country_code: ident_frame.attr('cc')) if ident_frame.attr('cc').present?
elsif ident_type == "birthday" && ident_country_code.blank?
at.merge!(ident_country_code: ident_frame.attr('cc'))
elsif ident_type.blank? && ident_country_code.blank?
at.merge!(ident_type: ident_frame.attr('type'))
at.merge!(ident_country_code: ident_frame.attr('cc')) if ident_frame.attr('cc').present?
if ident_frame.text == ident
if ident_type.present? && ident_country_code.present?
at.merge!(ident_type: ident_frame.attr('type'))
at.merge!(ident_country_code: ident_frame.attr('cc'))
elsif ident_country_code.blank? && org_priv.include?(ident_type) && org_priv.include?(ident_frame.attr('type'))
at.merge!(ident_country_code: ident_frame.attr('cc'), ident_type: ident_frame.attr('type'))
elsif ident_type == 'birthday' && !ident[/\A\d{4}-\d{2}-\d{2}\z/] && (Date.parse(ident) rescue false)
at.merge!(ident: ident_frame.text)
at.merge!(ident_country_code: ident_frame.attr('cc'))
elsif ident_type == 'birthday' && ident_country_code.blank?
at.merge!(ident_country_code: ident_frame.attr('cc'))
elsif ident_type.blank? && ident_country_code.blank?
at.merge!(ident_type: ident_frame.attr('type'))
at.merge!(ident_country_code: ident_frame.attr('cc'))
else
deny_ident_update
end
else
deny_ident_update
end
@ -203,7 +202,6 @@ class Epp::Contact < Contact
super(at)
end
# rubocop:enable Metrics/AbcSize
def statuses_attrs(frame, action)
status_list = status_list_from(frame)
@ -266,6 +264,6 @@ class Epp::Contact < Contact
private
def deny_ident_update
throw :epp_error, { code: '2306', msg: I18n.t(:ident_update_error) }
throw :epp_error, { code: '2308', msg: I18n.t(:ident_update_error) }
end
end