mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Do not require address in registrar area unless address_processing is enabled
#251
This commit is contained in:
parent
99a928fd3a
commit
8cc2d030b8
4 changed files with 110 additions and 45 deletions
|
@ -1,5 +1,6 @@
|
|||
class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
||||
before_action :init_epp_contact
|
||||
helper_method :address_processing?
|
||||
|
||||
def index
|
||||
authorize! :view, Depp::Contact
|
||||
|
@ -134,4 +135,8 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
|||
|
||||
params[:q][:valid_to_lteq] = ca_cache
|
||||
end
|
||||
|
||||
def address_processing?
|
||||
Contact.address_processing?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -150,18 +150,21 @@ module Depp
|
|||
postalInfo: {
|
||||
name: { value: name },
|
||||
org: { value: org_name },
|
||||
addr: {
|
||||
street: { value: street },
|
||||
city: { value: city },
|
||||
sp: { value: state },
|
||||
pc: { value: zip },
|
||||
cc: { value: country_code }
|
||||
}
|
||||
},
|
||||
voice: { value: phone },
|
||||
email: { value: email }
|
||||
}
|
||||
|
||||
if ::Contact.address_processing?
|
||||
hash[:postalInfo][:addr] = {
|
||||
street: { value: street },
|
||||
city: { value: city },
|
||||
sp: { value: state },
|
||||
pc: { value: zip },
|
||||
cc: { value: country_code },
|
||||
}
|
||||
end
|
||||
|
||||
hash[:id] = nil if code.blank?
|
||||
create_xml = Depp::Contact.epp_xml.create(hash, extension_xml(:create))
|
||||
|
||||
|
@ -182,36 +185,41 @@ module Depp
|
|||
self.phone = params[:phone]
|
||||
|
||||
self.org_name = params[:org_name]
|
||||
self.street = params[:street]
|
||||
self.city = params[:city]
|
||||
self.zip = params[:zip]
|
||||
self.state = params[:state]
|
||||
self.country_code = params[:country_code]
|
||||
|
||||
update_xml = Depp::Contact.epp_xml.update(
|
||||
{
|
||||
id: { value: id },
|
||||
chg: {
|
||||
postalInfo: {
|
||||
name: { value: name },
|
||||
org: { value: org_name },
|
||||
addr: {
|
||||
street: { value: street },
|
||||
city: { value: city },
|
||||
sp: { value: state },
|
||||
pc: { value: zip },
|
||||
cc: { value: country_code }
|
||||
}
|
||||
},
|
||||
voice: { value: phone },
|
||||
email: { value: email },
|
||||
authInfo: {
|
||||
pw: { value: password }
|
||||
}
|
||||
if ::Contact.address_processing?
|
||||
self.street = params[:street]
|
||||
self.city = params[:city]
|
||||
self.zip = params[:zip]
|
||||
self.state = params[:state]
|
||||
self.country_code = params[:country_code]
|
||||
end
|
||||
|
||||
attributes = {
|
||||
id: { value: id },
|
||||
chg: {
|
||||
postalInfo: {
|
||||
name: { value: name },
|
||||
org: { value: org_name },
|
||||
},
|
||||
voice: { value: phone },
|
||||
email: { value: email },
|
||||
authInfo: {
|
||||
pw: { value: password }
|
||||
}
|
||||
},
|
||||
extension_xml(:update)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if ::Contact.address_processing?
|
||||
attributes[:chg][:postalInfo][:addr] = {
|
||||
street: { value: street },
|
||||
city: { value: city },
|
||||
sp: { value: state },
|
||||
pc: { value: zip },
|
||||
cc: { value: country_code }
|
||||
}
|
||||
end
|
||||
|
||||
update_xml = Depp::Contact.epp_xml.update(attributes, extension_xml(:update))
|
||||
data = Depp::Contact.user.request(update_xml)
|
||||
handle_errors(data)
|
||||
end
|
||||
|
|
|
@ -4,21 +4,21 @@
|
|||
.panel-body
|
||||
.form-group
|
||||
.col-md-3.control-label
|
||||
= f.label :street, t(:street) + '*'
|
||||
= f.label :street, t(:street)
|
||||
.col-md-7
|
||||
= f.text_field :street, class: 'form-control', required: true
|
||||
= f.text_field :street, class: 'form-control', required: address_processing?
|
||||
|
||||
.form-group
|
||||
.col-md-3.control-label
|
||||
= f.label :city, t(:city) + '*'
|
||||
= f.label :city, t(:city)
|
||||
.col-md-7
|
||||
= f.text_field :city, class: 'form-control', required: true
|
||||
= f.text_field :city, class: 'form-control', required: address_processing?
|
||||
|
||||
.form-group
|
||||
.col-md-3.control-label
|
||||
= f.label :zip, t(:zip) + '*'
|
||||
= f.label :zip, t(:zip)
|
||||
.col-md-7
|
||||
= f.text_field :zip, class: 'form-control', required: true
|
||||
= f.text_field :zip, class: 'form-control', required: address_processing?
|
||||
|
||||
.form-group
|
||||
.col-md-3.control-label
|
||||
|
@ -28,9 +28,10 @@
|
|||
|
||||
.form-group
|
||||
.col-md-3.control-label
|
||||
= f.label :country_code, t(:country) + '*'
|
||||
= f.label :country_code, t(:country)
|
||||
.col-md-7
|
||||
- country_selected = f.object.persisted? ? f.object.country_code : 'EE'
|
||||
= f.select(:country_code, SortedCountry.all_options(country_selected),
|
||||
{ include_blank: true }, required: true)
|
||||
|
||||
= f.select(:country_code,
|
||||
SortedCountry.all_options(country_selected),
|
||||
{ include_blank: true },
|
||||
required: address_processing?)
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module RequiredAddressFieldsHelper
|
||||
def define_field_examples(attr_name)
|
||||
describe "#{attr_name} field" do
|
||||
let(:field) { page.find("[name='depp_contact[#{attr_name}]']") }
|
||||
|
||||
context 'when address processing is enabled' do
|
||||
before do
|
||||
allow(view).to receive(:address_processing?).and_return(true)
|
||||
end
|
||||
|
||||
it 'is required' do
|
||||
render
|
||||
expect(field[:required]).to eq('required')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when address processing is disabled' do
|
||||
before do
|
||||
allow(view).to receive(:address_processing?).and_return(false)
|
||||
end
|
||||
|
||||
it 'is optional' do
|
||||
render
|
||||
expect(field[:required]).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.describe 'registrar/contacts/form_partials/_address' do
|
||||
extend RequiredAddressFieldsHelper
|
||||
let(:contact) { instance_spy(Depp::Contact) }
|
||||
|
||||
before do
|
||||
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:depp_contact, contact, view, {}))
|
||||
end
|
||||
|
||||
required_address_attributes = %i(
|
||||
street
|
||||
city
|
||||
zip
|
||||
country_code
|
||||
)
|
||||
|
||||
required_address_attributes.each do |attr_name|
|
||||
define_field_examples(attr_name)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue