mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Merge branch 'registry-251' into registry-260
This commit is contained in:
commit
5318b129b0
7 changed files with 148 additions and 46 deletions
|
@ -1,5 +1,6 @@
|
||||||
class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
||||||
before_action :init_epp_contact
|
before_action :init_epp_contact
|
||||||
|
helper_method :address_processing?
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize! :view, Depp::Contact
|
authorize! :view, Depp::Contact
|
||||||
|
@ -134,4 +135,8 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
||||||
|
|
||||||
params[:q][:valid_to_lteq] = ca_cache
|
params[:q][:valid_to_lteq] = ca_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def address_processing?
|
||||||
|
Contact.address_processing?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -150,18 +150,21 @@ module Depp
|
||||||
postalInfo: {
|
postalInfo: {
|
||||||
name: { value: name },
|
name: { value: name },
|
||||||
org: { value: org_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 },
|
voice: { value: phone },
|
||||||
email: { value: email }
|
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?
|
hash[:id] = nil if code.blank?
|
||||||
create_xml = Depp::Contact.epp_xml.create(hash, extension_xml(:create))
|
create_xml = Depp::Contact.epp_xml.create(hash, extension_xml(:create))
|
||||||
|
|
||||||
|
@ -182,36 +185,41 @@ module Depp
|
||||||
self.phone = params[:phone]
|
self.phone = params[:phone]
|
||||||
|
|
||||||
self.org_name = params[:org_name]
|
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(
|
if ::Contact.address_processing?
|
||||||
{
|
self.street = params[:street]
|
||||||
id: { value: id },
|
self.city = params[:city]
|
||||||
chg: {
|
self.zip = params[:zip]
|
||||||
postalInfo: {
|
self.state = params[:state]
|
||||||
name: { value: name },
|
self.country_code = params[:country_code]
|
||||||
org: { value: org_name },
|
end
|
||||||
addr: {
|
|
||||||
street: { value: street },
|
attributes = {
|
||||||
city: { value: city },
|
id: { value: id },
|
||||||
sp: { value: state },
|
chg: {
|
||||||
pc: { value: zip },
|
postalInfo: {
|
||||||
cc: { value: country_code }
|
name: { value: name },
|
||||||
}
|
org: { value: org_name },
|
||||||
},
|
},
|
||||||
voice: { value: phone },
|
voice: { value: phone },
|
||||||
email: { value: email },
|
email: { value: email },
|
||||||
authInfo: {
|
authInfo: {
|
||||||
pw: { value: password }
|
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)
|
data = Depp::Contact.user.request(update_xml)
|
||||||
handle_errors(data)
|
handle_errors(data)
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,21 +4,21 @@
|
||||||
.panel-body
|
.panel-body
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= f.label :street, t(:street) + '*'
|
= f.label :street, t(:street)
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= f.text_field :street, class: 'form-control', required: true
|
= f.text_field :street, class: 'form-control', required: address_processing?
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= f.label :city, t(:city) + '*'
|
= f.label :city, t(:city)
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= f.text_field :city, class: 'form-control', required: true
|
= f.text_field :city, class: 'form-control', required: address_processing?
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= f.label :zip, t(:zip) + '*'
|
= f.label :zip, t(:zip)
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= f.text_field :zip, class: 'form-control', required: true
|
= f.text_field :zip, class: 'form-control', required: address_processing?
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
|
@ -28,9 +28,10 @@
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= f.label :country_code, t(:country) + '*'
|
= f.label :country_code, t(:country)
|
||||||
.col-md-7
|
.col-md-7
|
||||||
- country_selected = f.object.persisted? ? f.object.country_code : 'EE'
|
- country_selected = f.object.persisted? ? f.object.country_code : 'EE'
|
||||||
= f.select(:country_code, SortedCountry.all_options(country_selected),
|
= f.select(:country_code,
|
||||||
{ include_blank: true }, required: true)
|
SortedCountry.all_options(country_selected),
|
||||||
|
{ include_blank: true },
|
||||||
|
required: address_processing?)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-6= render 'registrar/contacts/partials/general'
|
.col-md-6= render 'registrar/contacts/partials/general'
|
||||||
.col-md-6= render 'registrar/contacts/partials/address'
|
.col-md-6= render 'registrar/contacts/partials/address' if Contact.address_processing?
|
||||||
.row
|
.row
|
||||||
.col-md-12= render 'registrar/contacts/partials/statuses', statuses: @contact.statuses
|
.col-md-12= render 'registrar/contacts/partials/statuses', statuses: @contact.statuses
|
||||||
.row
|
.row
|
||||||
|
|
|
@ -343,6 +343,7 @@ en:
|
||||||
city: 'City'
|
city: 'City'
|
||||||
street: 'Street'
|
street: 'Street'
|
||||||
zip: 'Postcode'
|
zip: 'Postcode'
|
||||||
|
state: State
|
||||||
org_name: 'Org name'
|
org_name: 'Org name'
|
||||||
failed_to_add_domain: 'Failed to add domain!'
|
failed_to_add_domain: 'Failed to add domain!'
|
||||||
domain_added: 'Domain added!'
|
domain_added: 'Domain added!'
|
||||||
|
|
|
@ -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
|
36
spec/views/registrar/contacts/show.haml_spec.rb
Normal file
36
spec/views/registrar/contacts/show.haml_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'registrar/contacts/show' do
|
||||||
|
let(:contact) { instance_spy(Depp::Contact, id: 1, name: 'test') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
assign(:contact, contact)
|
||||||
|
stub_template 'shared/_title' => ''
|
||||||
|
stub_template 'registrar/contacts/partials/_general' => ''
|
||||||
|
stub_template 'registrar/contacts/partials/_statuses' => ''
|
||||||
|
stub_template 'registrar/contacts/partials/_domains' => ''
|
||||||
|
stub_template 'registrar/contacts/partials/_address' => 'address info'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when address processing is enabled' do
|
||||||
|
before do
|
||||||
|
allow(Contact).to receive(:address_processing?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has address' do
|
||||||
|
render
|
||||||
|
expect(rendered).to have_text('address info')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when address processing is disabled' do
|
||||||
|
before do
|
||||||
|
allow(Contact).to receive(:address_processing?).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has no address' do
|
||||||
|
render
|
||||||
|
expect(rendered).to_not have_text('address info')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue