Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

19865-disallow-ting-restorations #2481

Merged
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
13 changes: 10 additions & 3 deletions legal-api/src/legal_api/services/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class BusinessBlocker(str, Enum):
BUSINESS_FROZEN = 'BUSINESS_FROZEN'
DRAFT_PENDING = 'DRAFT_PENDING'
NOT_IN_GOOD_STANDING = 'NOT_IN_GOOD_STANDING'
AMALGAMATING_BUSINESS = 'AMALGAMATING_BUSINESS'


class BusinessRequirement(str, Enum):
Expand Down Expand Up @@ -314,13 +315,15 @@ def get_allowable_filings_dict():
'fullRestoration': {
'legalTypes': ['BC', 'BEN', 'CC', 'ULC'],
'blockerChecks': {
'invalidStateFilings': ['continuationIn', 'continuationOut']
'invalidStateFilings': ['continuationIn', 'continuationOut'],
'business': [BusinessBlocker.AMALGAMATING_BUSINESS]
}
},
'limitedRestoration': {
'legalTypes': ['BC', 'BEN', 'CC', 'ULC'],
'blockerChecks': {
'invalidStateFilings': ['continuationIn', 'continuationOut']
'invalidStateFilings': ['continuationIn', 'continuationOut'],
'business': [BusinessBlocker.AMALGAMATING_BUSINESS]
}
}
}
Expand Down Expand Up @@ -598,7 +601,8 @@ def business_blocker_check(business: Business, is_ignore_draft_blockers: bool =
BusinessBlocker.DEFAULT: False,
BusinessBlocker.BUSINESS_FROZEN: False,
BusinessBlocker.DRAFT_PENDING: False,
BusinessBlocker.NOT_IN_GOOD_STANDING: False
BusinessBlocker.NOT_IN_GOOD_STANDING: False,
BusinessBlocker.AMALGAMATING_BUSINESS: False
}

if not business:
Expand All @@ -615,6 +619,9 @@ def business_blocker_check(business: Business, is_ignore_draft_blockers: bool =
if not business.good_standing:
business_blocker_checks[BusinessBlocker.NOT_IN_GOOD_STANDING] = True

if business.amalgamating_businesses.one_or_none():
business_blocker_checks[BusinessBlocker.AMALGAMATING_BUSINESS] = True

return business_blocker_checks


Expand Down
57 changes: 55 additions & 2 deletions legal-api/tests/unit/services/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
CORRECTION_AR, CHANGE_OF_REGISTRATION_TEMPLATE, RESTORATION, FILING_TEMPLATE, DISSOLUTION, PUT_BACK_ON, \
CONTINUATION_IN, CONSENT_CONTINUATION_OUT, CONTINUATION_OUT

from legal_api.models import Address, Filing
from legal_api.models import Address, Filing, AmalgamatingBusiness
from legal_api.models.business import Business, PartyRole, User

from legal_api.services.authz import BASIC_USER, COLIN_SVC_ROLE, STAFF_ROLE, PUBLIC_USER, \
Expand Down Expand Up @@ -674,7 +674,7 @@ def mock_auth(one, two): # pylint: disable=unused-argument; mocks of library me
('staff_historical', Business.State.HISTORICAL, 'incorporationApplication', None,
['CP', 'BC', 'BEN', 'CC', 'ULC', 'LLC'], 'staff', [STAFF_ROLE], False),

('staff_historical_allowed', Business.State.HISTORICAL, 'restoration', 'fullRestoration',
('staff_historical_alloweds', Business.State.HISTORICAL, 'restoration', 'fullRestoration',
['BC', 'BEN', 'CC', 'ULC'], 'staff', [STAFF_ROLE], True),

('staff_historical_allowed', Business.State.HISTORICAL, 'restoration', 'limitedRestoration',
Expand Down Expand Up @@ -1151,6 +1151,58 @@ def mock_auth(one, two): # pylint: disable=unused-argument; mocks of library me
filing_types = get_allowed_filings(business, state, legal_type, jwt)
assert filing_types == expected

@pytest.mark.parametrize(
'test_name,business_exists,state,legal_types,username,roles,expected',
[

# historical business - staff user
('staff_historical_cp', True, Business.State.HISTORICAL, ['CP'], 'staff', [STAFF_ROLE],
expected_lookup([FilingKey.COURT_ORDER,
FilingKey.REGISTRARS_NOTATION,
FilingKey.REGISTRARS_ORDER]),
),
('staff_historical_corps', True, Business.State.HISTORICAL, ['BC', 'BEN', 'CC', 'ULC'], 'staff', [STAFF_ROLE],
expected_lookup([FilingKey.COURT_ORDER,
FilingKey.REGISTRARS_NOTATION,
FilingKey.REGISTRARS_ORDER])),
('staff_historical_llc', True, Business.State.HISTORICAL, ['LLC'], 'staff', [STAFF_ROLE], []),
('staff_historical_firms', True, Business.State.HISTORICAL, ['SP', 'GP'], 'staff', [STAFF_ROLE],
expected_lookup([FilingKey.COURT_ORDER,
FilingKey.REGISTRARS_NOTATION,
FilingKey.REGISTRARS_ORDER])),

# historical business - general user
('general_user_historical_cp', True, Business.State.HISTORICAL, ['CP'], 'general', [BASIC_USER], []),
('general_user_historical_corps', True, Business.State.HISTORICAL, ['BC', 'BEN', 'CC', 'ULC'], 'general',
[BASIC_USER], []),
('general_user_historical_llc', True, Business.State.HISTORICAL, ['LLC'], 'general', [BASIC_USER], []),
('general_user_historical_firms', True, Business.State.HISTORICAL, ['SP', 'GP'], 'general', [BASIC_USER], []),
]
)

def test_get_allowed_filings_blocker_for_amalgamating_business(monkeypatch, app, session, jwt, test_name, business_exists, state,
legal_types, username, roles, expected):
"""Assert that get allowed returns valid filings when business is not in good standing."""
token = helper_create_jwt(jwt, roles=roles, username=username)
headers = {'Authorization': 'Bearer ' + token}

def mock_auth(one, two): # pylint: disable=unused-argument; mocks of library methods
return headers[one]

with app.test_request_context():
monkeypatch.setattr('flask.request.headers.get', mock_auth)

for legal_type in legal_types:
business = None
identifier = (f'BC{random.SystemRandom().getrandbits(0x58)}')[:9]
business = factory_business(identifier=identifier,
entity_type=legal_type,
state=state)

with patch.object(type(business), 'amalgamating_businesses', new_callable=PropertyMock) as mock_amalgamating_business:
mock_amalgamating_business = [{'role': AmalgamatingBusiness.Role.amalgamating.name, 'identifier': identifier}]
filing_types = get_allowed_filings(business, state, legal_type, jwt)
assert filing_types == expected

@pytest.mark.parametrize(
'test_name,business_exists,state,legal_types,username,roles,expected',
Expand Down Expand Up @@ -1231,6 +1283,7 @@ def mock_auth(one, two): # pylint: disable=unused-argument; mocks of library me
('general_user_historical_firms', True, Business.State.HISTORICAL, ['SP', 'GP'], 'general', [BASIC_USER], []),
]
)

def test_get_allowed_filings_blocker_not_in_good_standing(monkeypatch, app, session, jwt, test_name, business_exists, state,
legal_types, username, roles, expected):
"""Assert that get allowed returns valid filings when business is not in good standing."""
Expand Down
Loading