Skip to content

Commit

Permalink
19374 & 19375 amalgamation validaton fixes (bcgov#2397)
Browse files Browse the repository at this point in the history
  • Loading branch information
vysakh-menon-aot authored and JazzarKarim committed Mar 19, 2024
1 parent bb3209f commit 47c3271
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
7 changes: 5 additions & 2 deletions legal-api/src/legal_api/resources/v2/business/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ def get_businesses(identifier: str):
account_response,
)
if orgs := account_response.get("orgs"):
if str(orgs[0].get("id")) == q_account:
business_json["accountId"] = orgs[0].get("id")
# A business can be affiliated in multiple accounts (in user account as well as in gov staff account's)
# AccountService.get_account_by_affiliated_identifier will fetch all of it
# check one of it has `q_account`
if any(str(org.get('id')) == q_account for org in orgs):
business_json['accountId'] = q_account

return jsonify(business=business_json)

Expand Down
5 changes: 2 additions & 3 deletions legal-api/src/legal_api/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
from legal_api.models import LegalEntity
from legal_api.utils.datetime import datetime

from .authz import (
from .authz import ( # noqa: I001;
ACCOUNT_IDENTITY,
BASIC_USER,
COLIN_SVC_ROLE,
STAFF_ROLE,
SYSTEM_ROLE,
authorized,
get_account_by_affiliated_identifier,
has_roles,
)
) # noqa: I001;
from .bootstrap import AccountService, RegistrationBootstrapService
from .business_details_version import VersionedBusinessDetailsService
from .business_service import BusinessService
Expand Down
1 change: 0 additions & 1 deletion legal-api/src/legal_api/services/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from urllib.parse import urljoin

import jwt as pyjwt
import requests
from flask import current_app
from flask_jwt_oidc import JwtManager
from requests import Session, exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def validate_amalgamating_businesses( # pylint: disable=too-many-branches,too-m
"path": amalgamating_businesses_path,
}
)
elif _has_future_effective_filing(amalgamating_business):
elif _has_pending_filing(amalgamating_business):
msg.append(
{"error": f"{identifier} has a future effective filing.", "path": amalgamating_businesses_path}
{"error": f"{identifier} has a draft, pending or future effective filing.", "path": amalgamating_businesses_path}
)

if not is_staff:
Expand Down Expand Up @@ -217,14 +217,17 @@ def _is_business_affliated(identifier, account_id):
if (
(account_response := AccountService.get_account_by_affiliated_identifier(identifier))
and (orgs := account_response.get("orgs"))
and str(orgs[0].get("id")) == account_id
and any(str(org.get('id')) == account_id for org in orgs)
):
return True
return False


def _has_future_effective_filing(amalgamating_business: any):
if Filing.get_filings_by_status(amalgamating_business, [Filing.Status.PAID.value, Filing.Status.PENDING.value]):
def _has_pending_filing(amalgamating_business: any):
if Filing.get_filings_by_status(amalgamating_business.id, [
Filing.Status.DRAFT.value,
Filing.Status.PENDING.value,
Filing.Status.PAID.value]):
return True
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch("legal_api.models.legal_entity.LegalEntity.find_by_identifier", side_effect=mock_find_by_identifier)
Expand All @@ -1632,10 +1632,10 @@ def mock_find_by_identifier(identifier):

@pytest.mark.parametrize(
"test_status, expected_code, expected_msg",
[("FAIL", HTTPStatus.BAD_REQUEST, "BC1234567 has a future effective filing."), ("SUCCESS", None, None)],
[('FAIL', HTTPStatus.BAD_REQUEST, 'BC1234567 has a draft, pending or future effective filing.'), ("SUCCESS", None, None)],
)
def test_has_future_effective_filing(mocker, app, session, jwt, test_status, expected_code, expected_msg):
"""Assert valid amalgamating businesses has future effective filing."""
def test_has_pending_filing(mocker, app, session, jwt, test_status, expected_code, expected_msg):
"""Assert valid amalgamating businesses has draft, pending or future effective filing."""
filing = {"filing": {}}
filing["filing"]["header"] = {
"name": "amalgamationApplication",
Expand Down Expand Up @@ -1697,7 +1697,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch("legal_api.models.legal_entity.LegalEntity.find_by_identifier", side_effect=mock_find_by_identifier)
Expand Down Expand Up @@ -1760,7 +1760,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch(
Expand Down Expand Up @@ -1812,7 +1812,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch(
Expand Down Expand Up @@ -1864,7 +1864,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch(
Expand Down Expand Up @@ -1926,7 +1926,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch(
Expand Down Expand Up @@ -1991,7 +1991,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch(
Expand Down Expand Up @@ -2054,7 +2054,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch(
Expand Down Expand Up @@ -2114,7 +2114,7 @@ def mock_find_by_identifier(identifier):
"legal_api.services.filings.validations.amalgamation_application.validate_name_request", return_value=[]
)
mocker.patch(
"legal_api.services.filings.validations.amalgamation_application._has_future_effective_filing",
"legal_api.services.filings.validations.amalgamation_application._has_pending_filing",
return_value=False,
)
mocker.patch(
Expand Down

0 comments on commit 47c3271

Please sign in to comment.