Merge remote-tracking branch 'origin/registry-663' into registry-660

This commit is contained in:
Artur Beljajev 2018-01-18 11:07:25 +02:00
commit a9f04f6f0e
7 changed files with 79 additions and 11 deletions

View file

@ -19,24 +19,17 @@ authentication using electronic ID. Association through a business organisation
=end
class BusinessRegistryCache < ActiveRecord::Base
# 1. load domains by business
# 2. load domains by person
def associated_contacts
contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: 'EE').pluck(:id)
contact_ids += Contact.where(ident_type: 'priv', ident: ident, ident_country_code: ident_country_code).pluck(:id)
contact_ids
end
def associated_domain_ids
contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: ident_country_code).pluck(:id)
contact_ids += Contact.where(ident_type: 'priv', ident: ident, ident_country_code: ident_country_code).pluck(:id)
domain_ids = []
contact_ids = associated_contacts
unless contact_ids.blank?
domain_ids = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id)
end
domain_ids += Domain.where(registrant_id: contact_ids).pluck(:id)
domain_ids
end

View file

@ -0,0 +1,8 @@
first:
ident: 1234
ident_country_code: US
associated_businesses:
- 1234
retrieved_on: 2010-07-05 10:30
created_at: 2010-07-05 10:30
updated_at: 2010-07-05 10:30

20
test/fixtures/contacts.yml vendored Normal file
View file

@ -0,0 +1,20 @@
john:
name: John
ident: 1234
ident_type: priv
ident_country_code: US
registrar: acme
jane:
name: Jane
ident: 1234
ident_type: priv
ident_country_code: US
registrar: acme
acme_ltd:
name: Acme Ltd.
ident: 1234
ident_type: org
registrar: acme
ident_country_code: US

4
test/fixtures/domain_contacts.yml vendored Normal file
View file

@ -0,0 +1,4 @@
two_jane:
domain: two
contact: jane
type: AdminDomainContact

14
test/fixtures/domains.yml vendored Normal file
View file

@ -0,0 +1,14 @@
one:
name: one.test
registrar: valid
registrant: john
two:
name: two.test
registrar: valid
registrant: john
three:
name: three.test
registrar: valid
registrant: acme_ltd

View file

@ -14,3 +14,7 @@ admin:
country_code: US
roles:
- admin
registrant:
type: RegistrantUser
registrant_ident: US-1234

View file

@ -0,0 +1,25 @@
require 'test_helper'
class DomainsTest < ActionDispatch::IntegrationTest
def setup
login_as users(:registrant)
Setting.days_to_keep_business_registry_cache = 1
travel_to Time.zone.parse('2010-07-05')
end
def test_shows_domains_where_current_user_is_registrant
visit registrant_domains_url
assert_text 'one.test'
end
def test_shows_domains_where_current_user_is_contact_person
visit registrant_domains_url
assert_text 'two.test'
end
def test_shows_domains_where_current_user_has_associated_organizations
visit registrant_domains_url
assert_text 'three.test'
end
end