Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions legal-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion legal-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "legal-api"
version = "3.1.46"
version = "3.1.47"
description = ""
authors = [
{name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"}
Expand Down
12 changes: 11 additions & 1 deletion legal-api/src/legal_api/services/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
return any(bool(jwt.validate_roles(request_ctx.current_user, [role])) for role in roles)


def get_allowable_filings_dict(is_authorization: bool = False):
def get_allowable_filings_dict(is_authorization: bool = False): # noqa: PLR0912

Check failure on line 169 in legal-api/src/legal_api/services/authz.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 31 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=bcgov_lear&issues=AaFB3fdDUu7qVCf7x99d&open=AaFB3fdDUu7qVCf7x99d&pullRequest=4869
"""Return dictionary containing rules for when filings are allowed."""
# importing here to avoid circular dependencies
# pylint: disable=import-outside-toplevel
Expand Down Expand Up @@ -708,6 +708,16 @@
else:
del allowable_filings_dict[user_type][Business.State.ACTIVE.value][filing_type]

enabled_features = flags.value(
"enable-new-feature",
request_context.user,
request_context.account_id,
) or []
if "reviewImportedData" not in enabled_features:
for user_type_dict in allowable_filings_dict.values():
for business_state_dict in user_type_dict.values():
business_state_dict.pop("reviewImportedData", None)

# Remove some alteration blockers when authorization is not required
if not is_authorization:
for user_type_dict in allowable_filings_dict.values():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def validate(business: Business, imported_data: dict) -> Error:
filing_type,
allowed_types=["registeredOffice", "recordsOffice"],
required_types=[],
bc_req=False,
bc_req=True,

@meawong meawong Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating as records/registered offices require a BC address for delivery addresses.

)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ def validate(business: Business, # noqa: PLR0915, PLR0912, PLR0911
err = registration_validate(filing_json)

elif k == Filing.FILINGS["reviewImportedData"].get("name"):
err = review_imported_data_validate(business,filing_json)
enabled_features = flags.value("enable-new-feature", account_id=account_id) or []
if "reviewImportedData" not in enabled_features:
err = Error(HTTPStatus.FORBIDDEN, [{"error": "Review Imported Data filing is not enabled."}])
else:
err = review_imported_data_validate(business, filing_json)

elif k == Filing.FILINGS["changeOfRegistration"].get("name"):
err = change_of_registration_validate(business, filing_json)
Expand Down
2 changes: 1 addition & 1 deletion legal-api/tests/unit/resources/v2/test_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ def test_get_could_file(session, client, jwt, monkeypatch):
monkeypatch.setattr(
'legal_api.services.flags.value',
lambda flag, _user, _account_id: "changeOfLiquidators.appointLiquidator,changeOfLiquidators.ceaseLiquidator,changeOfLiquidators.changeAddressLiquidator,changeOfLiquidators.intentToLiquidate,changeOfLiquidators.liquidationReport,changeOfReceivers.amendReceiver,changeOfReceivers.appointReceiver,changeOfReceivers.ceaseReceiver,changeOfReceivers.changeAddressReceiver,dissolution.delay,transition"
if flag == 'enabled-specific-filings' else {}
if flag == 'enabled-specific-filings' else ['reviewImportedData'] if flag == 'enable-new-feature' else {}
)
monkeypatch.setattr(
'business_model.models.User.get_or_create_user_by_jwt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ def test_validate_offices_only(session):
assert err is None


def test_validate_rejects_review_imported_data_when_feature_is_disabled(session, monkeypatch):
"""Reject the filing when reviewImportedData is absent from the feature flag."""
business = _setup_business()
filing = _build_filing({
"offices": {
"registeredOffice": _valid_office(),
},
})
monkeypatch.setattr("legal_api.services.flags.value", lambda *args, **kwargs: [])

err = validate(business, filing)

assert err is not None
assert err.code == HTTPStatus.FORBIDDEN
assert err.msg == [{"error": "Review Imported Data filing is not enabled."}]


def test_validate_relationships_only(session):
"""Assert a filing containing relationships only passes validation."""
business = _setup_business()
Expand Down Expand Up @@ -153,6 +170,36 @@ def test_validate_offices_and_relationships(session):
assert err is None


@pytest.mark.parametrize(
"office_type,address_type",
[
("registeredOffice", "deliveryAddress"),
("registeredOffice", "mailingAddress"),
("recordsOffice", "deliveryAddress"),
("recordsOffice", "mailingAddress"),
],
)
def test_validate_requires_bc_region_for_office_addresses(session, office_type, address_type):
"""Require BC region for delivery addresses, but allow other regions for mailing addresses."""
business = _setup_business()
office = _valid_office()
office[address_type]["addressRegion"] = "AB"
filing = _build_filing({"offices": {office_type: office}})

err = validate(business, filing)

if address_type == "mailingAddress":
assert err is None
else:
expected_path = f"/filing/reviewImportedData/offices/{office_type}"
assert err is not None
assert err.code == HTTPStatus.BAD_REQUEST
assert any(
item["error"] == "Address Region must be 'BC'." and item["path"] == expected_path
for item in err.msg
)


def test_validate_rejects_unknown_director_identifier(session):
"""Assert a relationship identifier that is not an active director is rejected."""
business = _setup_business()
Expand Down
Loading
Loading