mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 03:30:33 +02:00
Updated disclosure
This commit is contained in:
parent
4e5aecb26d
commit
4800e0c315
11 changed files with 71 additions and 27 deletions
|
@ -38,7 +38,8 @@ module Epp::ContactsHelper
|
|||
def info_contact
|
||||
handle_errors(@contact) and return unless @contact
|
||||
handle_errors(@contact) and return unless rights?
|
||||
@disclosure = @contact.disclosure
|
||||
@disclosure = ContactDisclosure.default_values.merge(@contact.disclosure.as_hash)
|
||||
@disclosure_policy = @contact.disclosure.attributes_with_flag
|
||||
@owner = owner?(false)
|
||||
render 'epp/contacts/info'
|
||||
end
|
||||
|
@ -145,7 +146,7 @@ module Epp::ContactsHelper
|
|||
case type
|
||||
when :update
|
||||
# TODO: support for rem/add
|
||||
contact_hash = merge_attribute_hash(@ph[:chg], type)
|
||||
contact_hash = merge_attribute_hash(@ph[:chg], type).delete_if { |_k, v| v.empty? }
|
||||
else
|
||||
contact_hash = merge_attribute_hash(@ph, type)
|
||||
end
|
||||
|
|
|
@ -65,7 +65,7 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def ensure_disclosure
|
||||
create_disclosure!(ContactDisclosure.default_values) unless disclosure
|
||||
create_disclosure! unless disclosure
|
||||
end
|
||||
|
||||
def domains_snapshot
|
||||
|
|
|
@ -1,6 +1,24 @@
|
|||
class ContactDisclosure < ActiveRecord::Base
|
||||
belongs_to :contact
|
||||
|
||||
def attributes_with_flag
|
||||
attrs, policy = { name: name, email: email, phone: phone, address: address, org_name: org_name, fax: fax }, {}
|
||||
policy[0] = attrs.map { |k, v| k if v == false }.compact
|
||||
policy[1] = attrs.map { |k, v| k if v }.compact
|
||||
policy
|
||||
end
|
||||
|
||||
def as_hash
|
||||
{
|
||||
name: name,
|
||||
org_name: org_name,
|
||||
phone: phone,
|
||||
fax: fax,
|
||||
email: email,
|
||||
address: address
|
||||
}
|
||||
end
|
||||
|
||||
# value is true or false depending on disclosure flag
|
||||
# rules are the contents of disclose element
|
||||
class << self
|
||||
|
@ -26,7 +44,7 @@ class ContactDisclosure < ActiveRecord::Base
|
|||
disclosure_hash.each do |k, _v| # provides a correct flag to disclosure elements
|
||||
disclosure_hash[k] = value
|
||||
end
|
||||
default_values.merge(disclosure_hash)
|
||||
disclosure_hash
|
||||
end
|
||||
|
||||
private
|
||||
|
|
9
app/views/epp/contacts/_disclosure_policy.xml.builder
Normal file
9
app/views/epp/contacts/_disclosure_policy.xml.builder
Normal file
|
@ -0,0 +1,9 @@
|
|||
if @disclosure_policy
|
||||
@disclosure_policy.each do |k,v|
|
||||
xml.tag!('contact:disclose', 'flag' => k) do
|
||||
v.each do |attr|
|
||||
xml.tag!("contact:#{attr}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
address = @contact.address
|
||||
xml.tag!('contact:postalInfo', type: 'int') do
|
||||
xml.tag!('contact:name', @contact.name) if @disclosure.try(:name) || @owner
|
||||
xml.tag!('contact:org', @contact.org_name) if @disclosure.try(:org_name) || @owner
|
||||
xml.tag!('contact:name', @contact.name) if @disclosure.try(:[], :name) || @owner
|
||||
xml.tag!('contact:org', @contact.org_name) if @disclosure.try(:[], :org_name) || @owner
|
||||
if @disclosure.try(:addr) || @owner
|
||||
xml.tag!('contact:addr') do
|
||||
xml.tag!('contact:street', address.street) if address
|
||||
|
|
|
@ -22,7 +22,7 @@ xml.epp_head do
|
|||
xml.tag!('contact:pw', @contact.auth_info) # Doc says we have to return this but is it necessary?
|
||||
end
|
||||
end
|
||||
xml.tag!('contact:disclose', '123') if false
|
||||
xml << render('/epp/contacts/disclosure_policy')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class RemoveDefaultsFromDisclosure < ActiveRecord::Migration
|
||||
def change
|
||||
change_column :contact_disclosures, :phone, :boolean, :default => nil
|
||||
change_column :contact_disclosures, :fax, :boolean, :default => nil
|
||||
change_column :contact_disclosures, :email, :boolean, :default => nil
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20141124105221) do
|
||||
ActiveRecord::Schema.define(version: 20141127091027) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -41,9 +41,9 @@ ActiveRecord::Schema.define(version: 20141124105221) do
|
|||
|
||||
create_table "contact_disclosures", force: true do |t|
|
||||
t.integer "contact_id"
|
||||
t.boolean "phone", default: false
|
||||
t.boolean "fax", default: false
|
||||
t.boolean "email", default: false
|
||||
t.boolean "phone"
|
||||
t.boolean "fax"
|
||||
t.boolean "email"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "name"
|
||||
|
|
|
@ -134,11 +134,11 @@ describe 'EPP Contact', epp: true do
|
|||
response = epp_request(create_contact_xml(xml), :xml)
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
|
||||
expect(Contact.last.disclosure.name).to eq(true)
|
||||
expect(Contact.last.disclosure.org_name).to eq(true)
|
||||
expect(Contact.last.disclosure.name).to eq(nil)
|
||||
expect(Contact.last.disclosure.org_name).to eq(nil)
|
||||
expect(Contact.last.disclosure.phone).to eq(true)
|
||||
expect(Contact.last.disclosure.fax).to eq(false)
|
||||
expect(Contact.last.disclosure.email).to eq(true)
|
||||
expect(Contact.last.disclosure.fax).to eq(nil)
|
||||
expect(Contact.last.disclosure.email).to eq(nil)
|
||||
expect(Contact.last.disclosure.address).to eq(true)
|
||||
end
|
||||
end
|
||||
|
@ -212,6 +212,7 @@ describe 'EPP Contact', epp: true do
|
|||
it 'updates disclosure items' do
|
||||
Fabricate(:contact, code: 'sh8013', auth_info: '2fooBAR', registrar: zone, created_by_id: EppUser.first.id,
|
||||
disclosure: Fabricate(:contact_disclosure, phone: true, email: true))
|
||||
|
||||
xml = {
|
||||
id: { value: 'sh8013' },
|
||||
authInfo: { pw: { value: '2fooBAR' } }
|
||||
|
@ -336,7 +337,7 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
expect(contact.css('name').first).to eq(nil)
|
||||
expect(contact.css('chkData postalInfo name').first).to eq(nil)
|
||||
end
|
||||
|
||||
it 'discloses items to owner' do
|
||||
|
@ -393,9 +394,11 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
|
||||
expect(contact.css('phone').present?).to eq(false)
|
||||
expect(contact.css('email').present?).to eq(false)
|
||||
expect(contact.css('name').present?).to be(true)
|
||||
expect(contact.css('chkData phone')).to eq(contact.css('chkData disclose phone'))
|
||||
expect(contact.css('chkData phone').count).to eq(1)
|
||||
expect(contact.css('chkData email')).to eq(contact.css('chkData disclose email'))
|
||||
expect(contact.css('chkData email').count).to eq(1)
|
||||
expect(contact.css('postalInfo name').present?).to be(true)
|
||||
end
|
||||
|
||||
it 'doesn\'t display unassociated object without password' do
|
||||
|
|
|
@ -39,13 +39,13 @@ describe Contact do
|
|||
expect(@contact.valid?).to be true
|
||||
end
|
||||
|
||||
it 'should have default disclosure' do
|
||||
expect(@contact.disclosure.name).to be true
|
||||
expect(@contact.disclosure.org_name).to be true
|
||||
expect(@contact.disclosure.email).to be true
|
||||
expect(@contact.disclosure.phone).to be false
|
||||
expect(@contact.disclosure.fax).to be false
|
||||
expect(@contact.disclosure.address).to be false
|
||||
it 'should have empty disclosure' do
|
||||
expect(@contact.disclosure.name).to be nil
|
||||
expect(@contact.disclosure.org_name).to be nil
|
||||
expect(@contact.disclosure.email).to be nil
|
||||
expect(@contact.disclosure.phone).to be nil
|
||||
expect(@contact.disclosure.fax).to be nil
|
||||
expect(@contact.disclosure.address).to be nil
|
||||
end
|
||||
|
||||
it 'should have custom disclosure' do
|
||||
|
|
|
@ -27,7 +27,13 @@ module EppContactXmlHelper
|
|||
name: { value: 'John Doe Edited' }
|
||||
},
|
||||
voice: { value: '+372.7654321' },
|
||||
email: { value: 'edited@example.example' }
|
||||
email: { value: 'edited@example.example' },
|
||||
disclose: {
|
||||
value: {
|
||||
voice: { value: '' },
|
||||
email: { value: '' }
|
||||
}, attrs: { flag: '0' }
|
||||
}
|
||||
}
|
||||
}
|
||||
xml_params = defaults.deep_merge(xml_params)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue