Skip to content

Option for contact validation by company register#2917

Open
OlegPhenomenon wants to merge 8 commits into
masterfrom
option-for-contact-validation-by-company_register
Open

Option for contact validation by company register#2917
OlegPhenomenon wants to merge 8 commits into
masterfrom
option-for-contact-validation-by-company_register

Conversation

@OlegPhenomenon
Copy link
Copy Markdown
Contributor

@OlegPhenomenon OlegPhenomenon commented Apr 10, 2026

Add admin toggle for business contacts validation
Introduces validate_business_contacts SettingEntry (group: contacts)
that controls whether org contacts are validated against the Estonian
business register in Actions::ContactCreate#maybe_company_is_relevant.
When disabled, the validation is skipped entirely; the existing ENV
fallback is preserved.

Refs: internetee/registrant_center#166

@github-actions
Copy link
Copy Markdown

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

1 similar comment
@github-actions
Copy link
Copy Markdown

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

@vohmar
Copy link
Copy Markdown
Contributor

vohmar commented Apr 23, 2026

Copilot review @OlegPhenomenon

Summary
This PR adds two admin-controlled toggles to allow disabling business contact validation:

validate_business_contacts - Controls validation against Estonian business register
company_register_api_enabled - Controls access to company register API endpoints
Code Review
✅ Strengths
Clean implementation of feature toggle pattern:

Two new Settings entries with sensible defaults (true)
Proper migrations with safety assertions and rollback support
Well-placed guard clauses that short-circuit validation
Good test coverage:

New test file contact_create_test.rb with 3 focused test cases
Integration tests for API endpoints (companies, contacts, domains)
Tests verify both enabled and disabled states
Consistent pattern across controllers:

All API endpoints check company_register_api_enabled? helper
Graceful fallback to direct contacts when disabled
No breaking changes to existing functionality
Proper error handling:

Catches CompanyRegister::NotAvailableError exceptions
Provides sensible fallback behavior
⚠️ Issues & Observations
Database schema changes are large:

db/structure.sql has significant changes (checksum updates)
This is normal for Rails but ensure tests pass on fresh DB migrations
Minor code style consideration in contact_create.rb:

Ruby
def maybe_company_is_relevant
return true unless Setting.validate_business_contacts # Double negative logic
return true if ENV['allow_validate_business_contacts'] == 'false' # ENV check still exists
The ENV fallback is preserved, but consider documenting why both controls exist
The double negative (unless) on first line could be clearer
Test fixtures are good:

Both new settings added to test fixtures with proper defaults
Important for test isolation
API response changes are backward compatible:

Empty arrays/counters returned when disabled
Existing clients won't break
🔍 Questions for Author
Should the ENV variable allow_validate_business_contacts be deprecated in favor of the new Setting?
Are there admin UI pages for managing these new settings, or only accessible via Settings table directly?
Should there be separate settings, or should they be combined into one toggle?
✅ Recommendations
Merge-ready - Code quality is good, tests are thorough, and the feature is well-implemented
Consider adding a migration helper comment explaining the two settings' relationship
Verify all test suites pass in CI
Overall Assessment: This is a well-structured PR that adds useful admin controls with minimal risk and good backwards compatibility. 👍

@github-actions
Copy link
Copy Markdown

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

1 similar comment
@github-actions
Copy link
Copy Markdown

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

@github-actions
Copy link
Copy Markdown

🚀 Deploy Complete!

Property Value
App registry
Slot 2
URL https://registry2-dev.cloud.tld.ee
Namespace registry2-dev

(Environment ready for testing)

@github-actions
Copy link
Copy Markdown

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

2 similar comments
@github-actions
Copy link
Copy Markdown

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

@github-actions
Copy link
Copy Markdown

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

@OlegPhenomenon OlegPhenomenon force-pushed the option-for-contact-validation-by-company_register branch from 8ac2274 to f086b59 Compare May 4, 2026 13:28
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

3 similar comments
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

🚀 Deploy Complete!

Property Value
App registry
Slot 1
URL https://registry1-dev.cloud.tld.ee
Namespace registry1-dev

(Environment ready for testing)

Introduces `validate_business_contacts` SettingEntry (group: contacts)
that controls whether org contacts are validated against the Estonian
business register in Actions::ContactCreate#maybe_company_is_relevant.
When disabled, the validation is skipped entirely; the existing ENV
fallback is preserved.

Refs: internetee/registrant_center#166
strong_migrations cannot inspect raw execute blocks, so the
INSERT/DELETE statements for the validate_business_contacts setting
need an explicit safety_assured wrapper to pass the migration guard.

Refs: internetee/registrant_center#166
Covers Actions::ContactCreate#maybe_company_is_relevant:
- skips the company register lookup entirely when the setting is off
- honours REGISTERED status when the setting is on
- surfaces the company_not_registered EPP error otherwise

Refs: internetee/registrant_center#166
Introduces `company_register_api_enabled` SettingEntry (group: contacts)
that controls whether the registrant API queries the company register
service. When disabled, RegistrantUser#companies returns an empty array,
effectively skipping all company-based lookups in the registrant API
controllers (companies, domains, contacts).

Refs: internetee/registrant_center#166
The setting should only affect the registrant portal context
(registrant server <-> registry), not global company register usage
(EPP validation, phone checker jobs, etc).

Moves the `company_register_api_enabled` check from RegistrantUser#companies
into the three registrant API controllers:
- CompaniesController: returns empty list
- DomainsController: falls back to direct_domains
- ContactsController: falls back to direct_contacts
Replaces direct Setting.company_register_api_enabled calls in three
controllers with a shared predicate in BaseController. Also guards
do_need_update_contacts and update_contacts endpoints which call
companies internally.
The Setting.validate_business_contacts replaces the legacy ENV-based toggle. Drop the duplicate ENV check from contact_create and update the integration test to use the Setting accessor.
@OlegPhenomenon OlegPhenomenon force-pushed the option-for-contact-validation-by-company_register branch from f086b59 to 5435f40 Compare May 21, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants