diff --git a/legal-api/flags.json b/legal-api/flags.json index e4f5efde38..c74af71ff0 100644 --- a/legal-api/flags.json +++ b/legal-api/flags.json @@ -9,7 +9,7 @@ "enable-document-records": false, "enable-involuntary-dissolution-filter": false, "enable-new-ben-statements": false, - "enable-new-feature": [], + "enable-new-feature": ["reviewImportedData"], "enable-auth-v2-business": true, "enable-auth-v2-filing": true, "enable-permissions-for-action": false, diff --git a/legal-api/pyproject.toml b/legal-api/pyproject.toml index b151dcd4b1..4359741799 100644 --- a/legal-api/pyproject.toml +++ b/legal-api/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "legal-api" -version = "3.1.44" +version = "3.1.45" description = "" authors = [ {name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"} diff --git a/legal-api/src/legal_api/services/warnings/business/business_checks/corps.py b/legal-api/src/legal_api/services/warnings/business/business_checks/corps.py index 959f36b589..b2ec613242 100644 --- a/legal-api/src/legal_api/services/warnings/business/business_checks/corps.py +++ b/legal-api/src/legal_api/services/warnings/business/business_checks/corps.py @@ -15,6 +15,8 @@ """Business checks for corps.""" from business_model.models import Address, Business, OfficeType, PartyRole +from legal_api.services import flags +from legal_api.services.request_context import get_request_context from legal_api.services.warnings.business.business_checks import ( WARNING_MESSAGE_BASE, BusinessWarningCodes, @@ -38,14 +40,24 @@ def check_business(business: Business, is_staff: bool = False) -> list: """Check business data.""" result = [] - result.extend(check_offices(business)) - result.extend(check_directors(business)) + if is_review_imported_data_enabled(): + # missing address warnings are only actionable through the reviewImportedData filing (they block correction), + # so emit them only while that filing is enabled + result.extend(check_offices(business)) + result.extend(check_directors(business)) result.extend(check_amalgamating_business(business, is_staff)) result.extend(check_transition_application(business)) return result +def is_review_imported_data_enabled() -> bool: + """Return True when the reviewImportedData filing is enabled by the enable-new-feature flag.""" + request_context = get_request_context() + enabled_features = flags.value("enable-new-feature", request_context.user, request_context.account_id) or [] + return "reviewImportedData" in enabled_features + + def _with_data(warnings: list, data: dict) -> list: """Return copies of the warnings carrying ``data`` so the UI can identify the office/party to fix.""" return [{**warning, "data": data} for warning in warnings] diff --git a/legal-api/tests/unit/resources/v2/test_business.py b/legal-api/tests/unit/resources/v2/test_business.py index 051c18a8fa..9cd94152e3 100644 --- a/legal-api/tests/unit/resources/v2/test_business.py +++ b/legal-api/tests/unit/resources/v2/test_business.py @@ -622,6 +622,23 @@ def test_get_business_with_incomplete_info(session, client, jwt, test_name, lega assert len(rv_json['business']['warnings']) == 0 +def test_get_business_corps_missing_info_feature_flag_off(session, client, jwt, monkeypatch): + """Assert corps missing info warnings are not returned when reviewImportedData is not in enable-new-feature.""" + identifier = 'BC7654322' + business = factory_business(entity_type='BC', identifier=identifier) + business.no_dissolution = True + business.save() + flag_value = flags.value + monkeypatch.setattr('legal_api.services.flags.value', + lambda flag, *args, **kwargs: [] if flag == 'enable-new-feature' else flag_value(flag, *args, **kwargs)) + + rv = client.get(f'/api/v2/businesses/{identifier}', headers=create_header(jwt, [STAFF_ROLE], identifier)) + + assert rv.status_code == HTTPStatus.OK + assert rv.json['business']['warnings'] == [] + assert rv.json['business']['complianceWarnings'] == [] + + def test_get_business_with_court_orders(session, client, jwt): """Assert that the business info sets hasCourtOrders property.""" identifier = 'CP7654321' diff --git a/legal-api/tests/unit/resources/v2/test_business_tasks.py b/legal-api/tests/unit/resources/v2/test_business_tasks.py index 159701c4d6..8c924778a1 100644 --- a/legal-api/tests/unit/resources/v2/test_business_tasks.py +++ b/legal-api/tests/unit/resources/v2/test_business_tasks.py @@ -26,6 +26,7 @@ from freezegun import freeze_time from business_model.models import Business +from legal_api.services import flags from legal_api.services.authz import STAFF_ROLE from registry_schemas.example_data import ANNUAL_REPORT, FILING_HEADER, RESTORATION, TRANSITION_FILING_TEMPLATE from tests import integration_payment @@ -642,6 +643,21 @@ def test_review_imported_data_task(session, client, jwt, test_name, legal_type, for x in rv.json['tasks'] if legal_type != 'SP') +def test_review_imported_data_task_feature_flag_off(session, client, jwt, monkeypatch): + """Assert no reviewImportedData todo (and no missing info warnings) when the filing is not in enable-new-feature.""" + identifier = 'BC7654330' + factory_business(entity_type='BC', identifier=identifier) + flag_value = flags.value + monkeypatch.setattr('legal_api.services.flags.value', + lambda flag, *args, **kwargs: [] if flag == 'enable-new-feature' else flag_value(flag, *args, **kwargs)) + + rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) + + assert rv.status_code == HTTPStatus.OK + assert not any(x['task'].get('todo', {}).get('header', {}).get('name') == 'reviewImportedData' + for x in rv.json['tasks']) + + @pytest.mark.parametrize('test_name, business_restored, transition_completed, transition_task_expected', [ ('Transition application needed but not completed', True, False, True), ('Transition application needed and completed', True, True, False), diff --git a/legal-api/tests/unit/services/warnings/business/business_checks/test_corps.py b/legal-api/tests/unit/services/warnings/business/business_checks/test_corps.py index 15dd0299db..097fef3228 100644 --- a/legal-api/tests/unit/services/warnings/business/business_checks/test_corps.py +++ b/legal-api/tests/unit/services/warnings/business/business_checks/test_corps.py @@ -367,3 +367,25 @@ def test_warnings_carry_their_own_data(session): assert [x['data'] for x in result] == [{'officeType': 'registeredOffice'}, {'officeType': 'recordsOffice'}] assert 'data' not in check_address(factory_address('mailing', make_null_field_name='street'), Address.MAILING, BusinessWarningReferers.REGISTERED_OFFICE)[0] + + +@pytest.mark.parametrize("enabled_features, warnings_expected", [ + (['reviewImportedData'], True), + ([], False), + (None, False), # flag service unavailable +]) +def test_check_business_missing_info_gated_by_feature_flag(session, monkeypatch, enabled_features, warnings_expected): + """Assert office/director warnings are emitted only while reviewImportedData is in enable-new-feature.""" + business = factory_business(identifier="BC1234567", entity_type="BC") + add_director(business, factory_address('mailing', make_null_field_name='street'), factory_address('delivery')) + monkeypatch.setattr('legal_api.services.flags.value', lambda *args, **kwargs: enabled_features) + + with patch('business_model.models.business.Business.is_pending_amalgamating_business', return_value=None): + result = check_business(business) + + missing_info = [x for x in result if x['warningType'] == WarningType.MISSING_REQUIRED_BUSINESS_INFO] + if warnings_expected: + assert [x['code'] for x in missing_info] == ['NO_REGISTERED_OFFICE', 'NO_RECORDS_OFFICE', + 'NO_DIRECTOR_MAILING_ADDRESS_STREET'] + else: + assert missing_info == []