From 67082374ff9587dfd006238f5beac372dabfa928 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 14 Jan 2018 20:48:03 +0200 Subject: [PATCH 1/2] Show domains where current registrant user acts as a registrant #663 --- app/models/business_registry_cache.rb | 15 ++++--------- test/fixtures/business_registry_caches.yml | 8 +++++++ test/fixtures/contacts.yml | 20 +++++++++++++++++ test/fixtures/domain_contacts.yml | 4 ++++ test/fixtures/domains.yml | 14 ++++++++++++ test/fixtures/registrars.yml | 3 +++ test/fixtures/users.yml | 4 ++++ test/integration/registrant/domains_test.rb | 25 +++++++++++++++++++++ 8 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 test/fixtures/business_registry_caches.yml create mode 100644 test/fixtures/contacts.yml create mode 100644 test/fixtures/domain_contacts.yml create mode 100644 test/fixtures/domains.yml create mode 100644 test/integration/registrant/domains_test.rb diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index 8ec3e0786..2e7c06cc8 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -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 diff --git a/test/fixtures/business_registry_caches.yml b/test/fixtures/business_registry_caches.yml new file mode 100644 index 000000000..c55c98e0d --- /dev/null +++ b/test/fixtures/business_registry_caches.yml @@ -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 diff --git a/test/fixtures/contacts.yml b/test/fixtures/contacts.yml new file mode 100644 index 000000000..0300ef2b6 --- /dev/null +++ b/test/fixtures/contacts.yml @@ -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 diff --git a/test/fixtures/domain_contacts.yml b/test/fixtures/domain_contacts.yml new file mode 100644 index 000000000..3e1d01d62 --- /dev/null +++ b/test/fixtures/domain_contacts.yml @@ -0,0 +1,4 @@ +two_jane: + domain: two + contact: jane + type: AdminDomainContact diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml new file mode 100644 index 000000000..341f78d54 --- /dev/null +++ b/test/fixtures/domains.yml @@ -0,0 +1,14 @@ +one: + name: one.test + registrar: acme + registrant: john + +two: + name: two.test + registrar: acme + registrant: john + +three: + name: three.test + registrar: acme + registrant: acme_ltd diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index 52b2bbc00..960d47b13 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -10,6 +10,9 @@ DEFAULTS: &DEFAULTS valid: <<: *DEFAULTS +acme: + <<: *DEFAULTS + complete: <<: *DEFAULTS name: 2 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 860f06c13..856788de9 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -14,3 +14,7 @@ admin: country_code: US roles: - admin + +registrant: + type: RegistrantUser + registrant_ident: US-1234 diff --git a/test/integration/registrant/domains_test.rb b/test/integration/registrant/domains_test.rb new file mode 100644 index 000000000..6a1a76e39 --- /dev/null +++ b/test/integration/registrant/domains_test.rb @@ -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 From b363358d79430d1a57a502208792d5ff86c41c38 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 14 Jan 2018 21:01:19 +0200 Subject: [PATCH 2/2] Fix fixtures --- test/fixtures/domains.yml | 6 +++--- test/fixtures/registrars.yml | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml index 341f78d54..46a1e44e0 100644 --- a/test/fixtures/domains.yml +++ b/test/fixtures/domains.yml @@ -1,14 +1,14 @@ one: name: one.test - registrar: acme + registrar: valid registrant: john two: name: two.test - registrar: acme + registrar: valid registrant: john three: name: three.test - registrar: acme + registrar: valid registrant: acme_ltd diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index 960d47b13..52b2bbc00 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -10,9 +10,6 @@ DEFAULTS: &DEFAULTS valid: <<: *DEFAULTS -acme: - <<: *DEFAULTS - complete: <<: *DEFAULTS name: 2