diff --git a/legal-api/flags.json b/legal-api/flags.json index f07db3a6c2..b4e8e2e331 100644 --- a/legal-api/flags.json +++ b/legal-api/flags.json @@ -51,8 +51,6 @@ "dissolution.delay", "transition" ], - "enable-permissions-for-action": false, - "enabled-deeper-permission-action": false, "enable-edit-completing-party-permission": false, "enabled-specific-filings": "", "involuntary-dissolution-filter": { diff --git a/legal-api/pyproject.toml b/legal-api/pyproject.toml index 26cf893a40..c5c3940e35 100644 --- a/legal-api/pyproject.toml +++ b/legal-api/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "legal-api" -version = "3.1.84" +version = "3.1.85" description = "" authors = [ {name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"} diff --git a/legal-api/src/legal_api/resources/v2/business/business.py b/legal-api/src/legal_api/resources/v2/business/business.py index 111b0d2a2c..283e78d32f 100644 --- a/legal-api/src/legal_api/resources/v2/business/business.py +++ b/legal-api/src/legal_api/resources/v2/business/business.py @@ -302,10 +302,7 @@ def set_ar_reminder(identifier): f"You are not authorized to update the ar reminder for {identifier}."}), \ HTTPStatus.FORBIDDEN - if ( - flags.is_on("enable-permissions-for-action") and - PermissionService.check_user_permission(ListActionsPermissionsAllowed.AR_REMINDER_OPT_OUT.value) - ): + if PermissionService.check_user_permission(ListActionsPermissionsAllowed.AR_REMINDER_OPT_OUT.value): return ( jsonify({ "message": ( diff --git a/legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py b/legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py index e26e6001c3..4fa5b08971 100644 --- a/legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py +++ b/legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py @@ -677,11 +677,7 @@ def check_authorization(identifier, filing_json: dict, if err := PermissionService.check_filing_enabled(filing_type, filing_sub_type): return jsonify(err.msg), err.code - if ( - flags.is_on("enable-permissions-for-action") - and - not PermissionService.has_permissions_for_action(filing_type, legal_type, filing_sub_type) - ): + if not PermissionService.has_permissions_for_action(filing_type, legal_type, filing_sub_type): return ( jsonify({ "message": ( diff --git a/legal-api/src/legal_api/services/filings/validations/alteration.py b/legal-api/src/legal_api/services/filings/validations/alteration.py index 8ce3403f83..a2a8c099e5 100644 --- a/legal-api/src/legal_api/services/filings/validations/alteration.py +++ b/legal-api/src/legal_api/services/filings/validations/alteration.py @@ -19,7 +19,6 @@ from business_model.models import Business, PartyRole from legal_api.errors import Error -from legal_api.services import flags from legal_api.services.permissions import ListActionsPermissionsAllowed, PermissionService from legal_api.services.utils import get_bool, get_str @@ -40,7 +39,7 @@ def validate(business: Business, filing: dict) -> Error: # pylint: disable=too- if not business or not filing: return Error(HTTPStatus.BAD_REQUEST, [{"error": babel("A valid business and filing are required.")}]) msg = [] - if not business.good_standing and flags.is_on("enabled-deeper-permission-action"): + if not business.good_standing: required_permission = ListActionsPermissionsAllowed.OVERRIDE_NIGS.value message = "Permission Denied - You do not have permissions send not in good standing business in this filing." error = PermissionService.check_user_permission(required_permission, message=message) diff --git a/legal-api/src/legal_api/services/filings/validations/amalgamation_application.py b/legal-api/src/legal_api/services/filings/validations/amalgamation_application.py index 940cf00212..398c92c9dd 100644 --- a/legal-api/src/legal_api/services/filings/validations/amalgamation_application.py +++ b/legal-api/src/legal_api/services/filings/validations/amalgamation_application.py @@ -99,19 +99,18 @@ def validate(amalgamation_json: dict, account_id) -> Error | None: msg.extend(_validate_name_request_section(amalgamation_json, amalgamation_type, legal_type, filing_type)) - if flags.is_on("enabled-deeper-permission-action"): - err = validate_permission_and_completing_party( - None, - amalgamation_json, - filing_type, - msg, - {"check_name":False, - "check_email":True, - "check_address":False, - "check_document_email":True} - ) - if err: - return err + err = validate_permission_and_completing_party( + None, + amalgamation_json, + filing_type, + msg, + {"check_name":False, + "check_email":True, + "check_address":False, + "check_document_email":True} + ) + if err: + return err msg.extend(validate_party(amalgamation_json, amalgamation_type, filing_type, legal_type)) msg.extend(validate_parties_names(amalgamation_json, filing_type, legal_type)) msg.extend(validate_parties_addresses(amalgamation_json, filing_type)) @@ -486,7 +485,7 @@ def _validate_foreign_rules( # noqa: PLR0913 "error": f"A {legal_name} foreign corporation cannot be marked as Primary or Holding.", "path": amalgamating_business_path }) - elif flags.is_on("enabled-deeper-permission-action"): + else: permission_error = PermissionService.check_user_permission( ListActionsPermissionsAllowed.AML_OVERRIDES.value, message="Permission Denied - You do not have permissions to amalgamate a foreign corporation." @@ -497,30 +496,19 @@ def _validate_foreign_rules( # noqa: PLR0913 "path": amalgamating_business_path }) return msg - else: - msg.append({ - "error": (f"{legal_name} foreign corporation cannot " - "be amalgamated except by Registries staff."), - "path": amalgamating_business_path - }) - return msg def _check_aml_permission_or_default_error(msg: list, message: str, default_error: dict) -> bool: - if flags.is_on("enabled-deeper-permission-action"): - permission_error = PermissionService.check_user_permission( - ListActionsPermissionsAllowed.AML_OVERRIDES.value, - message=message - ) - if permission_error: - msg.append({ - "error": permission_error.msg[0].get("message"), - "path": default_error.get("path") - }) - return True - else: - msg.append(default_error) + permission_error = PermissionService.check_user_permission( + ListActionsPermissionsAllowed.AML_OVERRIDES.value, + message=message + ) + if permission_error: + msg.append({ + "error": permission_error.msg[0].get("message"), + "path": default_error.get("path") + }) return True return False diff --git a/legal-api/src/legal_api/services/filings/validations/change_of_registration.py b/legal-api/src/legal_api/services/filings/validations/change_of_registration.py index a633388ee3..3d3380fc24 100644 --- a/legal-api/src/legal_api/services/filings/validations/change_of_registration.py +++ b/legal-api/src/legal_api/services/filings/validations/change_of_registration.py @@ -18,7 +18,6 @@ from business_model.models import Business from legal_api.errors import Error -from legal_api.services import flags from legal_api.services.filings.validations.common_validations import ( find_updated_keys_for_firms, is_officer_proprietor_replace_valid, @@ -37,9 +36,6 @@ def _check_permission_for_change_of_registration(business: Business, filing: dict, filing_type: str) -> Error | None: """Check permissions for Change of Registration filing.""" - if not flags.is_on("enabled-deeper-permission-action"): - return None - for item in find_updated_keys_for_firms(business, filing, filing_type): if (item.get("is_dba") and ( diff --git a/legal-api/src/legal_api/services/filings/validations/common_validations.py b/legal-api/src/legal_api/services/filings/validations/common_validations.py index 15771e5406..79f5e6060f 100644 --- a/legal-api/src/legal_api/services/filings/validations/common_validations.py +++ b/legal-api/src/legal_api/services/filings/validations/common_validations.py @@ -581,12 +581,11 @@ def validate_court_order( if is_file_or_details_required or is_file_and_details_required: msg.extend(_validate_court_order_documents(court_order_path, court_order, is_file_and_details_required)) - if flags.is_on("enabled-deeper-permission-action"): - required_permission = ListActionsPermissionsAllowed.COURT_ORDER_POA.value - message = "Permission Denied - You do not have permissions add court order details in this filing." - permission_error = PermissionService.check_user_permission(required_permission, message=message) - if permission_error: - msg.append({"error": permission_error.msg[0].get("message", message), "path": court_order_path}) + required_permission = ListActionsPermissionsAllowed.COURT_ORDER_POA.value + message = "Permission Denied - You do not have permissions add court order details in this filing." + permission_error = PermissionService.check_user_permission(required_permission, message=message) + if permission_error: + msg.append({"error": permission_error.msg[0].get("message", message), "path": court_order_path}) return msg @@ -650,9 +649,6 @@ def check_good_standing_permission(business: Business) -> Error | None: if business.good_standing: return None - if not flags.is_on("enabled-deeper-permission-action"): - return None - required_permission = ListActionsPermissionsAllowed.OVERRIDE_NIGS.value message = "Permission Denied - You do not have permissions send not in good standing business in this filing." return PermissionService.check_user_permission(required_permission, message=message) diff --git a/legal-api/src/legal_api/services/filings/validations/dissolution.py b/legal-api/src/legal_api/services/filings/validations/dissolution.py index bc88e5a447..5c4ef6c7cb 100644 --- a/legal-api/src/legal_api/services/filings/validations/dissolution.py +++ b/legal-api/src/legal_api/services/filings/validations/dissolution.py @@ -21,7 +21,6 @@ from business_model.models import Address, Business, PartyRole from legal_api.errors import Error -from legal_api.services import flags from legal_api.services.filings.validations.common_validations import ( check_good_standing_permission, validate_court_order, @@ -76,10 +75,9 @@ def validate(business: Business, dissolution: dict) -> Error | None: dissolution_type = get_str(dissolution, "/filing/dissolution/dissolutionType") msg = [] - if flags.is_on("enabled-deeper-permission-action"): - err = _validate_dissolution_permission(business, dissolution, dissolution_type, filing_type, msg) - if err: - return err + err = _validate_dissolution_permission(business, dissolution, dissolution_type, filing_type, msg) + if err: + return err err = validate_dissolution_type(dissolution, business.legal_type) if err: diff --git a/legal-api/src/legal_api/services/filings/validations/incorporation_application.py b/legal-api/src/legal_api/services/filings/validations/incorporation_application.py index 67fc7946de..00539b0deb 100644 --- a/legal-api/src/legal_api/services/filings/validations/incorporation_application.py +++ b/legal-api/src/legal_api/services/filings/validations/incorporation_application.py @@ -20,7 +20,6 @@ from business_model.models import Business, PartyRole from legal_api.errors import Error -from legal_api.services import flags from legal_api.services.filings.validations.common_validations import ( validate_court_order, validate_effective_date, @@ -315,9 +314,6 @@ def _validate_incorporation_permission( msg: list ): """Validate the permission and completing party of the incorporation filing.""" - if not flags.is_on("enabled-deeper-permission-action"): - return None - if legal_type in Business.CORPS: return None diff --git a/legal-api/src/legal_api/services/filings/validations/registration.py b/legal-api/src/legal_api/services/filings/validations/registration.py index c3d5adaa81..724c543904 100644 --- a/legal-api/src/legal_api/services/filings/validations/registration.py +++ b/legal-api/src/legal_api/services/filings/validations/registration.py @@ -26,7 +26,7 @@ from business_model.models import Business, PartyRole, User from legal_api.core.filing import Filing from legal_api.errors import Error -from legal_api.services import STAFF_ROLE, NaicsService, flags +from legal_api.services import STAFF_ROLE, NaicsService from legal_api.services.authz import SBC_STAFF_ROLE from legal_api.services.filings.validations.common_validations import ( is_same_str, @@ -57,19 +57,18 @@ def validate(registration_json: dict) -> Error | None: filing_type = "registration" msg = [] - if flags.is_on("enabled-deeper-permission-action"): - err = validate_permission_and_completing_party( - None, - registration_json, - filing_type, - msg, - {"check_name":False, - "check_email":False, - "check_address":False, - "check_document_email":False} - ) - if err: - return err + err = validate_permission_and_completing_party( + None, + registration_json, + filing_type, + msg, + {"check_name":False, + "check_email":False, + "check_address":False, + "check_document_email":False} + ) + if err: + return err msg.extend(validate_name_request(registration_json, legal_type, filing_type)) msg.extend(validate_tax_id(registration_json)) @@ -130,7 +129,7 @@ def validate_party(filing: dict, legal_type: str, filing_type="registration") -> partner_parties = 0 invalid_roles = set() parties = filing["filing"][filing_type]["parties"] - if flags.is_on("enabled-deeper-permission-action") and filing_type == Filing.FilingTypes.REGISTRATION.value: + if filing_type == Filing.FilingTypes.REGISTRATION.value: msg.extend(validate_party_role_firms(parties, filing_type)) for party in parties: # pylint: disable=too-many-nested-blocks; for role in party.get("roles", []): @@ -228,20 +227,16 @@ def validate_start_date(filing: dict) -> list: lesser = now + relativedelta(years=-10) if not jwt.validate_roles(request_ctx.current_user, [STAFF_ROLE]) and start_date < lesser: - if flags.is_on("enabled-deeper-permission-action"): - permission_error = PermissionService.check_user_permission( - ListActionsPermissionsAllowed.FIRM_NO_MIN_START_DATE.value, - message="Permission Denied - You do not have permissions to set Start Date more than 10 years in the past." - ) - if permission_error: - msg.append({ - "error": permission_error.msg[0].get("message"), - "path": start_date_path - }) - return msg - else: - msg.append({"error": "Start date must be less than or equal to 10 years.", - "path": start_date_path}) + permission_error = PermissionService.check_user_permission( + ListActionsPermissionsAllowed.FIRM_NO_MIN_START_DATE.value, + message="Permission Denied - You do not have permissions to set Start Date more than 10 years in the past." + ) + if permission_error: + msg.append({ + "error": permission_error.msg[0].get("message"), + "path": start_date_path + }) + return msg if start_date > greater: msg.append({"error": "Start Date must be less than or equal to 90 days in the future.", "path": start_date_path}) diff --git a/legal-api/src/legal_api/services/filings/validations/validation.py b/legal-api/src/legal_api/services/filings/validations/validation.py index 4d35f6e9ce..84e3442a01 100644 --- a/legal-api/src/legal_api/services/filings/validations/validation.py +++ b/legal-api/src/legal_api/services/filings/validations/validation.py @@ -119,7 +119,7 @@ def _validate(business: Business, # noqa: PLR0915, PLR0912, PLR0911 if auth_received_errs: return Error(HTTPStatus.BAD_REQUEST, auth_received_errs) - if validate_staff_payment(filing_json) and flags.is_on("enabled-deeper-permission-action"): + if validate_staff_payment(filing_json): required_permission = ListActionsPermissionsAllowed.STAFF_PAYMENT.value message = "Permission Denied - You do not have permissions to add a staff payment in this filing." error = PermissionService.check_user_permission(required_permission, message) @@ -127,7 +127,7 @@ def _validate(business: Business, # noqa: PLR0915, PLR0912, PLR0911 return error # commenting out till certify stmt decision - # if validate_certify_name(filing_json) and flags.is_on('enabled-deeper-permission-action'): + # if validate_certify_name(filing_json): # required_permission = ListActionsPermissionsAllowed.EDITABLE_CERTIFY_NAME.value # noqa: ERA001 # message = f'Permission Denied - You do not have permissions to change certified by in this filing.' # noqa: ERA001 # error = PermissionService.check_user_permission(required_permission, message) # noqa: ERA001 diff --git a/legal-api/tests/conftest.py b/legal-api/tests/conftest.py index 539a7a29ff..aee4a0d7ab 100644 --- a/legal-api/tests/conftest.py +++ b/legal-api/tests/conftest.py @@ -35,10 +35,55 @@ from business_model.models import db as _db from legal_api import create_app, jwt as _jwt from legal_api.config import TestConfig +from legal_api.services.permissions import ( + ListActionsPermissionsAllowed, + ListFilingsPermissionsAllowed, + PermissionService, +) postgres = PostgresContainer("postgres:18-alpine") +@pytest.fixture +def authorized_filing_validation_user(mocker): + """Provide an authorized user for filing validation tests.""" + validation_permissions = [ + ListActionsPermissionsAllowed.AML_OVERRIDES.value, + ListActionsPermissionsAllowed.AR_REMINDER_OPT_OUT.value, + ListActionsPermissionsAllowed.COURT_ORDER_POA.value, + ListActionsPermissionsAllowed.FIRM_EDITABLE_DBA.value, + ListActionsPermissionsAllowed.FIRM_NO_MIN_START_DATE.value, + ListActionsPermissionsAllowed.FIRM_REPLACE_PERSON.value, + ListActionsPermissionsAllowed.OVERRIDE_NIGS.value, + ListActionsPermissionsAllowed.STAFF_PAYMENT.value, + ListFilingsPermissionsAllowed.DISSOLUTION_ADMIN_FILING.value, + ListFilingsPermissionsAllowed.DISSOLUTION_DELAY_FILING.value, + ListFilingsPermissionsAllowed.DISSOLUTION_FIRM_FILING.value, + ListFilingsPermissionsAllowed.DISSOLUTION_INVOLUNTARY_FILING.value, + ListFilingsPermissionsAllowed.DISSOLUTION_VOLUNTARY_FILING.value, + ] + mocker.patch.object( + PermissionService, + "get_authorized_permissions_for_user", + return_value=validation_permissions, + ) + return validation_permissions + + +@pytest.fixture +def authorized_business_filing_user(mocker, authorized_filing_validation_user): + """Provide a user authorized to submit business filings.""" + permissions = authorized_filing_validation_user + [ + permission.value for permission in ListFilingsPermissionsAllowed + ] + mocker.patch.object( + PermissionService, + "get_authorized_permissions_for_user", + return_value=permissions, + ) + return permissions + + # Models default many timestamp columns to ``func.now()`` which Postgres # resolves to the transaction start time. Per-test transaction isolation # means every row a test creates would share the same timestamp, breaking diff --git a/legal-api/tests/unit/resources/v2/test_business_filings/test_draft_rebase_guards.py b/legal-api/tests/unit/resources/v2/test_business_filings/test_draft_rebase_guards.py index 212753f8c3..8dad3c07af 100644 --- a/legal-api/tests/unit/resources/v2/test_business_filings/test_draft_rebase_guards.py +++ b/legal-api/tests/unit/resources/v2/test_business_filings/test_draft_rebase_guards.py @@ -49,7 +49,7 @@ def _mock_draft_rebase_flag(monkeypatch, enabled, bypass_types=('annualReport',)): - """Mock the draftRebaseChecks value and the bypass allowlist, pin the permission flag off. + """Mock the draftRebaseChecks value and the bypass allowlist. Every other flag is delegated. The default allowlist covers the annualReport drafts these tests use, since ownership enforcement is scoped to it. @@ -58,8 +58,6 @@ def _mock_draft_rebase_flag(monkeypatch, enabled, bypass_types=('annualReport',) flag_value = flags.value def _is_on(flag, *args, **kwargs): - if flag == 'enable-permissions-for-action': - return False return flag_is_on(flag, *args, **kwargs) def _value(flag, *args, **kwargs): diff --git a/legal-api/tests/unit/resources/v2/test_business_filings/test_filings.py b/legal-api/tests/unit/resources/v2/test_business_filings/test_filings.py index 58e9466b0f..d212221b48 100644 --- a/legal-api/tests/unit/resources/v2/test_business_filings/test_filings.py +++ b/legal-api/tests/unit/resources/v2/test_business_filings/test_filings.py @@ -635,7 +635,9 @@ def test_post_authorized_draft_ar(session, client, jwt): assert rv.status_code == HTTPStatus.CREATED -def test_post_not_authorized_draft_ar(app, session, client, jwt, requests_mock): +def test_post_not_authorized_draft_ar( + app, session, client, jwt, requests_mock, authorized_business_filing_user +): """Assert that a unpaid filing can be posted.""" identifier = 'CP7654321' factory_business(identifier) @@ -649,7 +651,9 @@ def test_post_not_authorized_draft_ar(app, session, client, jwt, requests_mock): assert rv.status_code == HTTPStatus.UNAUTHORIZED -def test_post_not_allowed_historical(app, session, client, jwt, requests_mock): +def test_post_not_allowed_historical( + app, session, client, jwt, requests_mock, authorized_business_filing_user +): """Assert that a filing is not allowed for historical business.""" identifier = 'CP7654321' factory_business(identifier, state=Business.State.HISTORICAL) @@ -1987,7 +1991,8 @@ def test_create_invoice_forwards_account_linking_key(session, requests_mock, cli ('sbc_finance_staff', SBC_FINANCE_STAFF_ROLE, True, '12345', None, None), ]) def test_create_invoice_forwards_account_id(session, requests_mock, client, jwt, monkeypatch, - test_name, role, feature_on, account_id, linking_key, expected_account): + test_name, role, feature_on, account_id, linking_key, expected_account, + authorized_business_filing_user): """Assert that create_invoice forwards a real Account-Id to pay-api only for callers authorized through auth.""" mock_new_feature(monkeypatch, 'authV2AccountId', feature_on) identifier = 'CP1234567' @@ -2547,11 +2552,6 @@ def test_dod(session, requests_mock, client, jwt, monkeypatch, test_name, legal_ lambda flag, _user=None, _account_id=None: enabled_filings if flag == 'enabled-specific-filings' else {} ) - monkeypatch.setattr( - 'legal_api.services.flags.is_on', - lambda flag: True - if flag == 'enabled-deeper-permission-action' else {} - ) dod = copy.deepcopy(FILING_HEADER) del dod['filing']['header']['routingSlipNumber'] del dod['filing']['header']['waiveFees'] @@ -2632,11 +2632,6 @@ def test_ta(session, requests_mock, client, jwt, monkeypatch, test_name, legal_t lambda flag, _user=None, _account_id=None: enabled_filings if flag == 'enabled-specific-filings' else [] ) - monkeypatch.setattr( - 'legal_api.services.flags.is_on', - lambda flag: True - if flag == 'enabled-deeper-permission-action' else {} - ) ta = copy.deepcopy(TRANSITION_FILING_TEMPLATE) ta['filing']['business']['identifier'] = identifier ta['filing']['business']['legalType'] = legal_type diff --git a/legal-api/tests/unit/services/filings/validations/alteration/test_court_order.py b/legal-api/tests/unit/services/filings/validations/alteration/test_court_order.py index 3421b35408..0d90dfccf6 100644 --- a/legal-api/tests/unit/services/filings/validations/alteration/test_court_order.py +++ b/legal-api/tests/unit/services/filings/validations/alteration/test_court_order.py @@ -21,6 +21,8 @@ from tests.unit.models import factory_business +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + @pytest.mark.parametrize('invalid_court_order', [ { diff --git a/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_basic.py b/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_basic.py index 746ac9bef8..f1823f65f4 100644 --- a/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_basic.py +++ b/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_basic.py @@ -27,6 +27,8 @@ from tests.unit.services.filings.validations.change_of_director import add_director, setup_business from registry_schemas.example_data import CHANGE_OF_DIRECTORS, FILING_HEADER +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + # Sentinel for cases whose blank/whitespace rule moved into business-schemas: the filing is now # rejected by schema validation (HTTP 422) instead of the legal-api business check (HTTP 400). diff --git a/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_directors_dates.py b/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_directors_dates.py index 6170ccb0b8..3fa67634fc 100644 --- a/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_directors_dates.py +++ b/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_directors_dates.py @@ -30,6 +30,8 @@ from tests.unit.services.filings.validations import lists_are_equal from tests.unit.services.filings.validations.change_of_director import add_director, setup_business +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + NOW = datetime(2025, 1, 1, 12, 0, tzinfo=timezone.utc) FOUNDING_DATE = NOW - datedelta.YEAR LAST_COD_DATE_SAME_AS_FOUNDING = FOUNDING_DATE diff --git a/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_directors_ids.py b/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_directors_ids.py index 58069981b9..a47b29d63d 100644 --- a/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_directors_ids.py +++ b/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_directors_ids.py @@ -31,6 +31,8 @@ setup_business, ) +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + FOUNDING_DATE = datetime.utcnow() - datedelta.datedelta(years=10) APPOINTMENT_DATE = (datetime.utcnow() - datedelta.datedelta(years=5)).date().isoformat() diff --git a/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_relationships.py b/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_relationships.py index c2b926fd6f..ff4f47382c 100644 --- a/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_relationships.py +++ b/legal-api/tests/unit/services/filings/validations/change_of_director/test_validation_relationships.py @@ -26,6 +26,8 @@ from tests.unit.services.filings.validations import lists_are_equal from tests.unit.services.filings.validations.change_of_director import add_director, build_cod_filing, setup_business +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + FOUNDING_DATE = datetime.utcnow() - datedelta.datedelta(years=10) APPOINTMENT_DATE = (datetime.utcnow() - datedelta.datedelta(years=5)).date().isoformat() diff --git a/legal-api/tests/unit/services/filings/validations/test_agm_extension.py b/legal-api/tests/unit/services/filings/validations/test_agm_extension.py index eae617ec84..40ffc8b275 100644 --- a/legal-api/tests/unit/services/filings/validations/test_agm_extension.py +++ b/legal-api/tests/unit/services/filings/validations/test_agm_extension.py @@ -24,6 +24,8 @@ from registry_schemas.example_data import FILING_HEADER from tests.unit.models import factory_business +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + @pytest.mark.parametrize( 'test_name, founding_date, agm_ext_json, expected_code, message', diff --git a/legal-api/tests/unit/services/filings/validations/test_agm_location_change.py b/legal-api/tests/unit/services/filings/validations/test_agm_location_change.py index 8db8dffcd2..7409e38e66 100644 --- a/legal-api/tests/unit/services/filings/validations/test_agm_location_change.py +++ b/legal-api/tests/unit/services/filings/validations/test_agm_location_change.py @@ -23,6 +23,8 @@ from registry_schemas.example_data import AGM_LOCATION_CHANGE, FILING_HEADER from tests.unit.models import factory_business +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + # Sentinel for cases whose blank/whitespace rule moved into business-schemas: the filing is now # rejected by schema validation (HTTP 422) instead of the legal-api business check (HTTP 400). diff --git a/legal-api/tests/unit/services/filings/validations/test_alteration.py b/legal-api/tests/unit/services/filings/validations/test_alteration.py index 2f4e079ba3..6dc4b42bd2 100644 --- a/legal-api/tests/unit/services/filings/validations/test_alteration.py +++ b/legal-api/tests/unit/services/filings/validations/test_alteration.py @@ -779,7 +779,6 @@ def court_order_permission_check(required_permission, message=None): return mock_check_user_permission(required_permission, message) with ( - patch.object(flags, 'is_on', return_value=True), patch.object(Business, 'good_standing', new_callable =lambda: good_standing), patch.object(PermissionService, 'check_user_permission', mock_check_user_permission), patch.object(PermissionService, 'check_user_permission', side_effect=court_order_permission_check) diff --git a/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py b/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py index 93d63452d9..bf9d0d715b 100644 --- a/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py +++ b/legal-api/tests/unit/services/filings/validations/test_amalgamation_application.py @@ -43,6 +43,8 @@ from tests.unit.services.filings.validations import create_party, create_party_address, lists_are_equal from tests.unit.services.utils import jwt_request_context +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + class MockResponse: """Mock http response.""" @@ -985,15 +987,17 @@ def test_in_future_effective_amalgamation_filing(mocker, app, session, jwt, @pytest.mark.parametrize( - 'test_status, flag_enabled, has_permission, expected_code, expected_msg', + 'test_status, is_affiliated, has_permission, expected_code, expected_msg', [ - ('FAIL_FLAG_OFF', False, False, HTTPStatus.BAD_REQUEST, ['BC1234567', 'BC7654321']), - ('SUCCESS_AFFILIATED', False, False, None, None), - ('FAIL_FLAG_ON_WITH_PERMISSION', True, False, HTTPStatus.BAD_REQUEST, 'BC1234567'), - ('SUCCESS_FLAG_ON_WITH_PERMISSION', True, True, None, None) + ('UNAFFILIATED_NO_PERMISSION', False, False, HTTPStatus.BAD_REQUEST, + 'Permission Denied - You do not have permissions to amalgamate an unaffiliated business.'), + ('UNAFFILIATED_WITH_PERMISSION', False, True, None, None), + ('AFFILIATED', True, False, None, None) ] ) -def test_is_business_affliated(mocker, app, session, jwt, test_status, flag_enabled, has_permission, expected_code, expected_msg): +def test_amalgamating_business_affiliation_permission( + mocker, app, session, jwt, test_status, is_affiliated, has_permission, expected_code, expected_msg +): """Assert valid amalgamating businesses is affliated.""" account_id = '123456' filing = _get_amalg_template() @@ -1020,13 +1024,18 @@ def mock_find_by_identifier(identifier): return_value=False) mocker.patch('business_model.models.business.Business.find_by_identifier', side_effect=mock_find_by_identifier) mocker.patch('legal_api.resources.v2.business.business.AccountService.get_account_by_affiliated_identifier', - return_value={'orgs': [{'id': account_id}]} if test_status in 'SUCCESS_AFFILIATED' else {}) + return_value={'orgs': [{'id': account_id}]} if is_affiliated else {}) - mocker.patch.object(flags, 'is_on', return_value=flag_enabled) + permission_message = ( + 'Permission Denied - You do not have permissions to amalgamate an unaffiliated business.' + ) - permission_error = None if has_permission else Error( - HTTPStatus.BAD_REQUEST, [{'message': 'Permission Denied - You do not have permissions to amalgamate an unaffiliated business.'}]) - mocker.patch.object(PermissionService, 'check_user_permission', return_value=permission_error) + def check_permission(_permission, message=None): + if not has_permission and message == permission_message: + return Error(HTTPStatus.BAD_REQUEST, [{'message': message}]) + return None + + mocker.patch.object(PermissionService, 'check_user_permission', side_effect=check_permission) mocker.patch('legal_api.services.filings.validations.common_validations.AccountService.get_contacts', return_value={'contacts': [{'email': 'test@example.com'}]}) @@ -1038,27 +1047,23 @@ def mock_find_by_identifier(identifier): assert not err else: assert expected_code == err.code - if isinstance(expected_msg, list): - assert (f'{expected_msg[0]} is not affiliated with the currently selected BC Registries account.' == - err.msg[0]['error']) - assert (f'{expected_msg[1]} is not affiliated with the currently selected BC Registries account.' == - err.msg[1]['error']) - else: - error_msg = err.msg[0].get('error') or err.msg[0].get('message') - assert 'Permission Denied - You do not have permissions to amalgamate an unaffiliated business.' == error_msg + error_msg = err.msg[0].get('error') or err.msg[0].get('message') + assert expected_msg == error_msg @pytest.mark.parametrize( - 'test_status, flag_enabled, has_permission, expected_code, expected_msg', + 'test_status, good_standing, has_permission, expected_code, expected_msg', [ - ('FAIL_FLAG_OFF', False, False, HTTPStatus.BAD_REQUEST, ['BC1234567', 'BC7654321']), - ('SUCCESS_GOOD_STANDING', False, False, None, None), - ('FAIL_FLAG_ON_WITH_PERMISSION', True, False, HTTPStatus.BAD_REQUEST, 'BC1234567'), - ('SUCCESS_FLAG_ON_WITH_PERMISSION', True, True, None, None) + ('NOT_GOOD_STANDING_NO_PERMISSION', False, False, HTTPStatus.BAD_REQUEST, + 'Permission Denied - You do not have permissions to amalgamate a business not in good standing.'), + ('NOT_GOOD_STANDING_WITH_PERMISSION', False, True, None, None), + ('GOOD_STANDING', True, False, None, None) ] ) -def test_is_business_in_good_standing(mocker, app, session, jwt, test_status, flag_enabled, has_permission, expected_code, expected_msg): +def test_amalgamating_business_good_standing_permission( + mocker, app, session, jwt, test_status, good_standing, has_permission, expected_code, expected_msg +): """Assert valid amalgamating businesses is in good standing.""" account_id = '123456' filing = _get_amalg_template() @@ -1076,12 +1081,11 @@ def test_is_business_in_good_standing(mocker, app, session, jwt, test_status, fl def mock_find_by_identifier(identifier): utc_now = datetime.now(timezone.utc) - is_good_standing = test_status in ( 'SUCCESS_GOOD_STANDING', 'SUCCESS_FLAG_ON_WITH_PERMISSION') return Business(identifier=identifier, legal_type=Business.LegalTypes.BCOMP.value, state=Business.State.ACTIVE, founding_date=utc_now, - restoration_expiry_date=utc_now if not is_good_standing else None) + restoration_expiry_date=utc_now if not good_standing else None) mocker.patch('legal_api.services.filings.validations.amalgamation_application.validate_name_request', return_value=[]) @@ -1092,11 +1096,16 @@ def mock_find_by_identifier(identifier): mocker.patch('business_model.models.business.Business.find_by_identifier', side_effect=mock_find_by_identifier) - mocker.patch.object(flags, 'is_on', return_value=flag_enabled) + permission_message = ( + 'Permission Denied - You do not have permissions to amalgamate a business not in good standing.' + ) - permission_error = None if has_permission else Error( - HTTPStatus.BAD_REQUEST, [{'message': 'Permission Denied - You do not have permissions to amalgamate business which is not in good standing.'}]) - mocker.patch.object(PermissionService, 'check_user_permission', return_value=permission_error) + def check_permission(_permission, message=None): + if not has_permission and message == permission_message: + return Error(HTTPStatus.BAD_REQUEST, [{'message': message}]) + return None + + mocker.patch.object(PermissionService, 'check_user_permission', side_effect=check_permission) mocker.patch('legal_api.services.filings.validations.common_validations.AccountService.get_contacts', return_value={'contacts': [{'email': 'test@example.com'}]}) @@ -1108,12 +1117,8 @@ def mock_find_by_identifier(identifier): assert not err else: assert expected_code == err.code - if isinstance(expected_msg, list): - assert f'{expected_msg[0]} is not in good standing.' == err.msg[0]['error'] - assert f'{expected_msg[1]} is not in good standing.' == err.msg[1]['error'] - else: - error_msg = err.msg[0].get('error') or err.msg[0].get('message') - assert 'Permission Denied - You do not have permissions to amalgamate business which is not in good standing.' == error_msg + error_msg = err.msg[0].get('error') or err.msg[0].get('message') + assert expected_msg == error_msg @pytest.mark.parametrize( @@ -1170,17 +1175,15 @@ def mock_find_by_identifier(identifier): @pytest.mark.parametrize( - 'test_status, role, flag_enabled, has_permission, expected_code, expected_msg', + 'test_status, role, has_permission, expected_code, expected_msg', [ - ('FAIL_FLAG_OFF', BASIC_USER, False, False, HTTPStatus.BAD_REQUEST, - 'Foreign Co. foreign corporation cannot be amalgamated except by Registries staff.'), - ('SUCCESS', STAFF_ROLE, False, False, None, None), - ('FAIL_FLAG_ON_NO_PERMISSION', BASIC_USER, True, False, HTTPStatus.BAD_REQUEST, + ('FAIL_NO_PERMISSION', BASIC_USER, False, HTTPStatus.BAD_REQUEST, 'Permission Denied - You do not have permissions to amalgamate a foreign corporation.'), - ('SUCCESS_FLAG_ON_WITH_PERMISSION', BASIC_USER, True, True, None, None) + ('SUCCESS_WITH_PERMISSION', BASIC_USER, True, None, None), + ('SUCCESS_STAFF', STAFF_ROLE, False, None, None) ] ) -def test_amalgamating_foreign_business(mocker, app, session, jwt, test_status, role, flag_enabled, has_permission, expected_code, expected_msg): +def test_amalgamating_foreign_business(mocker, app, session, jwt, test_status, role, has_permission, expected_code, expected_msg): """Assert valid amalgamating foreign business.""" account_id = '123456' filing = _get_amalg_template() @@ -1199,11 +1202,14 @@ def mock_find_by_identifier(identifier): return_value=True) mocker.patch('business_model.models.business.Business.find_by_identifier', side_effect=mock_find_by_identifier) - mocker.patch.object(flags, 'is_on', return_value=flag_enabled) + permission_message = 'Permission Denied - You do not have permissions to amalgamate a foreign corporation.' - permission_error = None if has_permission else Error( - HTTPStatus.BAD_REQUEST, [{'message': 'Permission Denied - You do not have permissions to amalgamate a foreign corporation.'}]) - mocker.patch.object(PermissionService, 'check_user_permission', return_value=permission_error) + def check_permission(_permission, message=None): + if not has_permission and role != STAFF_ROLE and message == permission_message: + return Error(HTTPStatus.BAD_REQUEST, [{'message': message}]) + return None + + mocker.patch.object(PermissionService, 'check_user_permission', side_effect=check_permission) mocker.patch('legal_api.services.filings.validations.common_validations.AccountService.get_contacts', return_value={'contacts': [{'email': 'test@example.com'}]}) @@ -1954,16 +1960,15 @@ def test_validate_amalgamation_effective_date( @pytest.mark.parametrize( - 'test_name, flag_enabled, permission_error, expected_code, expected_msg', + 'test_name, permission_error, expected_code, expected_msg', [ - ('SUCCESS_FLAG_ON', True, None, None, None), - ('SUCCESS_FLAG_OFF', False, None, None, None), - ('FAIL_PERMISSION_ERROR', True, Error(HTTPStatus.FORBIDDEN, [{'error': 'Permission denied.'}]), + ('SUCCESS', None, None, None), + ('FAIL_PERMISSION_ERROR', Error(HTTPStatus.FORBIDDEN, [{'error': 'Permission denied.'}]), HTTPStatus.FORBIDDEN, 'Permission denied.'), ] ) -def test_amalgamation_permission_and_completing_party_flag(mocker, app, session, test_name, flag_enabled, permission_error, expected_code, expected_msg): - """Test validate_permission_and_completing_party is called when flag is enabled.""" +def test_amalgamation_permission_and_completing_party(mocker, app, session, test_name, permission_error, expected_code, expected_msg): + """Test validate_permission_and_completing_party is always called.""" account_id = '123456' filing = {'filing': {}} filing['filing']['header'] = { @@ -1990,28 +1995,23 @@ def test_amalgamation_permission_and_completing_party_flag(mocker, app, session, mocker.patch('legal_api.services.filings.validations.amalgamation_application.validate_offices_addresses', return_value=[]) mocker.patch('legal_api.services.filings.validations.amalgamation_application.validate_amalgamation_court_order', return_value=[]) - mocker.patch.object(flags, 'is_on', return_value=flag_enabled) mock_validate_permission = mocker.patch( 'legal_api.services.filings.validations.amalgamation_application.validate_permission_and_completing_party', return_value=permission_error) with app.test_request_context(headers={'account-id': account_id}): err = validate(None, filing, account_id) - if flag_enabled: - mock_validate_permission.assert_called_once() - call_args = mock_validate_permission.call_args - assert call_args[0][0] is None - assert call_args[0][1] == filing - assert call_args[0][2] == 'amalgamationApplication' - check_options = call_args[0][4] - - assert check_options.get('check_name') is False - assert check_options.get('check_email') is True - assert check_options.get('check_address') is False - assert check_options.get('check_document_email') is True - else: - # When flag is off - mock_validate_permission.assert_not_called() + mock_validate_permission.assert_called_once() + call_args = mock_validate_permission.call_args + assert call_args[0][0] is None + assert call_args[0][1] == filing + assert call_args[0][2] == 'amalgamationApplication' + check_options = call_args[0][4] + + assert check_options.get('check_name') is False + assert check_options.get('check_email') is True + assert check_options.get('check_address') is False + assert check_options.get('check_document_email') is True if expected_code: assert err is not None assert err.code == expected_code @@ -2068,10 +2068,11 @@ def mock_find_by_identifier(identifier): ('HISTORICAL', f'Cannot amalgamate with {COLIN_IDENTIFIER} which is in historical state.'), ('FUTURE_EFFECTIVE', f'{COLIN_IDENTIFIER} has a draft, pending or future effective filing.'), ('FROZEN', f'{COLIN_IDENTIFIER} is frozen.'), - ('NOT_AFFILIATED', f'{COLIN_IDENTIFIER} is not affiliated with the currently ' - 'selected BC Registries account.'), - ('NOT_GOOD_STANDING', f'{COLIN_IDENTIFIER} is not in good standing.'), - ('GOOD_STANDING_UNKNOWN', f'{COLIN_IDENTIFIER} is not in good standing.'), + ('NOT_AFFILIATED', 'Permission Denied - You do not have permissions to amalgamate an unaffiliated business.'), + ('NOT_GOOD_STANDING', + 'Permission Denied - You do not have permissions to amalgamate a business not in good standing.'), + ('GOOD_STANDING_UNKNOWN', + 'Permission Denied - You do not have permissions to amalgamate a business not in good standing.'), ('OUT_OF_SCOPE_TYPE', f'A business with identifier:{COLIN_IDENTIFIER} not found.'), ('COLIN_404', f'A business with identifier:{COLIN_IDENTIFIER} not found.'), ('COLIN_500', f'Unable to verify {COLIN_IDENTIFIER} - COLIN is unavailable, try again.'), @@ -2105,10 +2106,28 @@ def test_colin_amalgamating_business(mocker, app, session, jwt, test_status, exp 'legal_api.services.filings.validations.amalgamation_application.colin.get_snapshot', return_value=snapshot_responses.get(test_status, _mock_colin_snapshot_response())) + permission_check = mocker.patch.object( + PermissionService, + 'check_user_permission', + side_effect=lambda _permission, message=None: ( + Error(HTTPStatus.BAD_REQUEST, [{'message': message}]) + if ( + test_status in ('NOT_AFFILIATED', 'NOT_GOOD_STANDING', 'GOOD_STANDING_UNKNOWN') + and message == expected_msg + ) + else None + ) + ) + with jwt_request_context(app, jwt, [BASIC_USER], 'basic-user', account_id): err = validate(None, filing, account_id) get_snapshot.assert_called_once_with(COLIN_IDENTIFIER) + if test_status in ('NOT_AFFILIATED', 'NOT_GOOD_STANDING', 'GOOD_STANDING_UNKNOWN'): + assert any( + call.kwargs.get('message') == expected_msg + for call in permission_check.call_args_list + ) if expected_msg is None: assert not err @@ -2357,18 +2376,24 @@ def mock_find_by_identifier(identifier): return filing -def test_expro_amalgamating_business_staff_only(mocker, app, session, jwt): - """Assert a non-staff user cannot amalgamate an extraprovincial.""" +def test_expro_amalgamating_business_without_override_permission(mocker, app, session, jwt): + """Assert a non-staff user without override permission cannot amalgamate an extraprovincial.""" account_id = '123456' filing = _setup_basic_expro_amalgamation(mocker) filing['filing']['amalgamationApplication']['nameRequest']['nrNumber'] = 'NR 1234567' + permission_error = Error( + HTTPStatus.BAD_REQUEST, + [{'message': 'Permission Denied - You do not have permissions to amalgamate a foreign corporation.'}] + ) + mocker.patch.object(PermissionService, 'check_user_permission', return_value=permission_error) with jwt_request_context(app, jwt, [BASIC_USER], 'basic-user', account_id): err = validate(None, filing, account_id) assert err.code == HTTPStatus.BAD_REQUEST - assert ('EXPRO TEST COMPANY LTD. foreign corporation cannot be amalgamated except by Registries staff.' - in [x['error'] for x in err.msg]) + assert 'Permission Denied - You do not have permissions to amalgamate a foreign corporation.' in [ + x.get('error') or x.get('message') for x in err.msg + ] def test_expro_name_not_adoptable(mocker, app, session, jwt): diff --git a/legal-api/tests/unit/services/filings/validations/test_amalgamation_out.py b/legal-api/tests/unit/services/filings/validations/test_amalgamation_out.py index d1295d8e23..bb0ed470c6 100644 --- a/legal-api/tests/unit/services/filings/validations/test_amalgamation_out.py +++ b/legal-api/tests/unit/services/filings/validations/test_amalgamation_out.py @@ -26,6 +26,8 @@ from registry_schemas.example_data import FILING_HEADER, CONSENT_AMALGAMATION_OUT, AMALGAMATION_OUT from tests.unit.models import factory_business, factory_completed_filing, get_cco_expiry_date +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + date_format = '%Y-%m-%d' legal_name = 'Test name request' diff --git a/legal-api/tests/unit/services/filings/validations/test_change_of_liquidators.py b/legal-api/tests/unit/services/filings/validations/test_change_of_liquidators.py index 939c04d976..76c474b476 100644 --- a/legal-api/tests/unit/services/filings/validations/test_change_of_liquidators.py +++ b/legal-api/tests/unit/services/filings/validations/test_change_of_liquidators.py @@ -24,6 +24,8 @@ from tests.unit.models import factory_business from registry_schemas.example_data import CHANGE_OF_LIQUIDATORS, FILING_HEADER +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + @pytest.mark.parametrize( 'test_name, roles, expected_code, expected_msg', diff --git a/legal-api/tests/unit/services/filings/validations/test_change_of_registration.py b/legal-api/tests/unit/services/filings/validations/test_change_of_registration.py index a03b3a1532..35833aa933 100644 --- a/legal-api/tests/unit/services/filings/validations/test_change_of_registration.py +++ b/legal-api/tests/unit/services/filings/validations/test_change_of_registration.py @@ -31,6 +31,8 @@ from tests.unit.services.utils import jwt_request_context from tests.unit.models import factory_business +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + now = datetime.now().strftime('%Y-%m-%d') @@ -402,10 +404,15 @@ def test_change_of_registration_dba_proprietor_permission(mock_flags, app, sessi user.save() extra_claims = {'firstname': 'Joe P', 'lastname': 'Swanson'} + permission_error = Error( + HTTPStatus.FORBIDDEN, + [{'message': 'Permission Denied - You do not have permissions edit DBA in this filing.'}] + ) if expect_forbidden else None with patch.object(NameXService, 'query_nr_number', return_value=MockResponse(nr_res)): with patch.object(NaicsService, 'find_by_code', return_value=naics_response): - with jwt_request_context(app, jwt, roles, login_source=login_source, extra_claims=extra_claims): - err = validate(business, filing) + with patch.object(PermissionService, 'check_user_permission', return_value=permission_error): + with jwt_request_context(app, jwt, roles, login_source=login_source, extra_claims=extra_claims): + err = validate(business, filing) if expect_forbidden: assert err diff --git a/legal-api/tests/unit/services/filings/validations/test_common_validations.py b/legal-api/tests/unit/services/filings/validations/test_common_validations.py index 8bc80edf2b..ff1082af8d 100644 --- a/legal-api/tests/unit/services/filings/validations/test_common_validations.py +++ b/legal-api/tests/unit/services/filings/validations/test_common_validations.py @@ -23,8 +23,8 @@ from legal_api.errors import Error from business_model.models import Business, Filing, Party, PartyRole, ShareClass from business_model.models.share_series import ShareSeries -from legal_api.services import NameXService, flags -from legal_api.services.permissions import PermissionService +from legal_api.services import NameXService +from legal_api.services.permissions import ListActionsPermissionsAllowed, PermissionService import pytest import registry_schemas from registry_schemas.example_data import ( @@ -1202,25 +1202,20 @@ def test_validate_email_surrounding_whitespace_rejected_by_schema(session, email (True, None), (False, 'Permission Denied'), ]) -def test_validate_court_order_with_flag_on(session, has_permission, expected_error_msg): - """ - Test court order validation with flag ON - """ +def test_validate_court_order_permission(session, has_permission, expected_error_msg): + """Test court order permission validation.""" court_order = { 'fileNumber': 'Valid file number', 'orderDate': '2021-01-30T09:56:01+01:00', 'effectOfOrder': 'planOfArrangement' } - permission_error = Error( - HTTPStatus.FORBIDDEN, - [{'message': 'Permission Denied - You do not have permissions add court order details in this filing.'}] - ) if not has_permission else None + permissions = ( + [ListActionsPermissionsAllowed.COURT_ORDER_POA.value] + if has_permission else [] + ) - with ( - patch.object(flags, 'is_on', return_value=True), - patch.object(PermissionService, 'check_user_permission', return_value=permission_error) - ): + with patch.object(PermissionService, 'get_authorized_permissions_for_user', return_value=permissions): result = validate_court_order('/filing/alteration/courtOrder', court_order) if has_permission: diff --git a/legal-api/tests/unit/services/filings/validations/test_consent_amalgamation_out.py b/legal-api/tests/unit/services/filings/validations/test_consent_amalgamation_out.py index f0c8bb8274..36ad60e404 100644 --- a/legal-api/tests/unit/services/filings/validations/test_consent_amalgamation_out.py +++ b/legal-api/tests/unit/services/filings/validations/test_consent_amalgamation_out.py @@ -25,6 +25,8 @@ from registry_schemas.example_data import FILING_HEADER, CONSENT_AMALGAMATION_OUT from tests.unit.models import factory_business, factory_completed_filing, get_cco_expiry_date +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + legal_name = 'Test name request' diff --git a/legal-api/tests/unit/services/filings/validations/test_consent_continuation_out.py b/legal-api/tests/unit/services/filings/validations/test_consent_continuation_out.py index 46c210ae8b..c44c8c3852 100644 --- a/legal-api/tests/unit/services/filings/validations/test_consent_continuation_out.py +++ b/legal-api/tests/unit/services/filings/validations/test_consent_continuation_out.py @@ -25,6 +25,8 @@ from registry_schemas.example_data import FILING_HEADER, CONSENT_CONTINUATION_OUT from tests.unit.models import factory_business, factory_completed_filing, get_cco_expiry_date +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + legal_name = 'Test name request' diff --git a/legal-api/tests/unit/services/filings/validations/test_continuation_in.py b/legal-api/tests/unit/services/filings/validations/test_continuation_in.py index 54383ecc04..6e3fd1d420 100644 --- a/legal-api/tests/unit/services/filings/validations/test_continuation_in.py +++ b/legal-api/tests/unit/services/filings/validations/test_continuation_in.py @@ -30,6 +30,8 @@ from tests.unit.services.filings.validations import create_party, create_party_address, lists_are_equal +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + class MockResponse: """Mock http response.""" diff --git a/legal-api/tests/unit/services/filings/validations/test_continuation_out.py b/legal-api/tests/unit/services/filings/validations/test_continuation_out.py index def920bb1b..ca60dd5533 100644 --- a/legal-api/tests/unit/services/filings/validations/test_continuation_out.py +++ b/legal-api/tests/unit/services/filings/validations/test_continuation_out.py @@ -27,6 +27,8 @@ from tests.unit.models import factory_business, factory_completed_filing, get_cco_expiry_date +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + date_format = '%Y-%m-%d' legal_name = 'Test name request' diff --git a/legal-api/tests/unit/services/filings/validations/test_correction_firms.py b/legal-api/tests/unit/services/filings/validations/test_correction_firms.py index 39bc8b12dc..c6af1149a1 100644 --- a/legal-api/tests/unit/services/filings/validations/test_correction_firms.py +++ b/legal-api/tests/unit/services/filings/validations/test_correction_firms.py @@ -29,6 +29,8 @@ from tests.unit.models import factory_business, factory_completed_filing from tests.unit.services.utils import jwt_request_context +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + CHANGE_OF_REGISTRATION_APPLICATION = copy.deepcopy(CHANGE_OF_REGISTRATION_TEMPLATE) GP_CORRECTION_REGISTRATION_APPLICATION = copy.deepcopy(CORRECTION_REGISTRATION) diff --git a/legal-api/tests/unit/services/filings/validations/test_correction_ia.py b/legal-api/tests/unit/services/filings/validations/test_correction_ia.py index 5b5767e7bb..bb24eb3fd7 100644 --- a/legal-api/tests/unit/services/filings/validations/test_correction_ia.py +++ b/legal-api/tests/unit/services/filings/validations/test_correction_ia.py @@ -62,6 +62,8 @@ from tests.unit.services.filings.validations import lists_are_equal from tests.unit.services.utils import jwt_request_context +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + date_format = '%Y-%m-%d' INCORPORATION_APPLICATION = copy.deepcopy(INCORPORATION_FILING_TEMPLATE) diff --git a/legal-api/tests/unit/services/filings/validations/test_court_order.py b/legal-api/tests/unit/services/filings/validations/test_court_order.py index 96afe95ddb..e35a388a61 100644 --- a/legal-api/tests/unit/services/filings/validations/test_court_order.py +++ b/legal-api/tests/unit/services/filings/validations/test_court_order.py @@ -33,6 +33,8 @@ from tests.unit.services.filings.validations import lists_are_equal from tests.unit.services.utils import mock_new_feature +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + def _mock_file_size(monkeypatch, file_size): """Serve a valid letter-size PDF that reports the given size.""" diff --git a/legal-api/tests/unit/services/filings/validations/test_dissolution.py b/legal-api/tests/unit/services/filings/validations/test_dissolution.py index f4b464d383..c828410b5e 100644 --- a/legal-api/tests/unit/services/filings/validations/test_dissolution.py +++ b/legal-api/tests/unit/services/filings/validations/test_dissolution.py @@ -34,6 +34,8 @@ from tests.unit.services.filings.test_utils import _upload_file, mock_drs_get_document from tests.unit.services.filings.validations import create_party, create_party_address, lists_are_equal +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + @pytest.mark.parametrize( 'test_status, legal_type, dissolution_type, identifier, expected_code, expected_msg', @@ -661,14 +663,14 @@ def test_dissolution_effective_date(session, test_name, @pytest.mark.parametrize( - 'test_name, good_standing, has_permission, flag_enabled, expected_code, expected_msg', + 'test_name, good_standing, has_permission, expected_code, expected_msg', [ - ('SUCCESS_GOOD_STANDING_WITH_FLAG', True, False, True, None, None), - ('SUCCESS_NOT_GOOD_STANDING_WITH_PERMISSION', False, True, True, None, None), - ('FAIL_NOT_GOOD_STANDING_NO_PERMISSION_WITH_FLAG', False, False, True, + ('SUCCESS_GOOD_STANDING', True, False, None, None), + ('SUCCESS_NOT_GOOD_STANDING_WITH_PERMISSION', False, True, None, None), + ('FAIL_NOT_GOOD_STANDING_NO_PERMISSION', False, False, HTTPStatus.FORBIDDEN, 'Permission Denied - You do not have permissions send not in good standing business in this filing.') ]) -def test_dissolution_good_standing_permission(session, test_name, good_standing, has_permission, flag_enabled, expected_code, expected_msg): +def test_dissolution_good_standing_permission(session, test_name, good_standing, has_permission, expected_code, expected_msg): """Test good standing validation in voluntary dissolution.""" business = Business(identifier='BC1234567', legal_type='BC') filing = copy.deepcopy(FILING_HEADER) @@ -685,12 +687,10 @@ def test_dissolution_good_standing_permission(session, test_name, good_standing, ) with ( - patch.object(flags, 'is_on', return_value=flag_enabled), patch.object(Business, 'good_standing', new_callable=lambda: good_standing), patch.object(PermissionService, 'check_user_permission', return_value=permission_error), patch.object(dissolution, 'validate_dissolution_parties_roles', return_value=None), patch.object(dissolution, 'validate_affidavit', return_value=[]), - patch.object(dissolution, 'check_good_standing_permission', return_value=permission_error if not good_standing and not has_permission and flag_enabled else None), patch.object(dissolution, 'validate_permission_and_completing_party', return_value=None), patch.object(dissolution, '_check_dissolution_permission', return_value=None), ): diff --git a/legal-api/tests/unit/services/filings/validations/test_incorporation_application.py b/legal-api/tests/unit/services/filings/validations/test_incorporation_application.py index 85a8de0f11..5a8b4aa89b 100644 --- a/legal-api/tests/unit/services/filings/validations/test_incorporation_application.py +++ b/legal-api/tests/unit/services/filings/validations/test_incorporation_application.py @@ -38,6 +38,8 @@ from legal_api.services.filings.validations.incorporation_application import validate_coop_parties_mailing_address, validate_parties_names from tests.unit import MockResponse +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + # setup identifier = 'NR 1234567' @@ -1918,44 +1920,38 @@ def _build_incorporation_filing_json(): @pytest.mark.parametrize( - 'test_name, flag_enabled, permission_error, expected_code, expected_msg', + 'test_name, permission_error, expected_code, expected_msg', [ - ('SUCCESS_FLAG_ON', True, None, None, None), - ('SUCCESS_FLAG_OFF', False, None, None, None), - ('FAIL_PERMISSION_ERROR', True, Error(HTTPStatus.FORBIDDEN, [{'error': 'Permission denied.'}]), + ('SUCCESS', None, None, None), + ('FAIL_PERMISSION_ERROR', Error(HTTPStatus.FORBIDDEN, [{'error': 'Permission denied.'}]), HTTPStatus.FORBIDDEN, 'Permission denied.'), ] ) -def test_incorporation_permission_and_completing_party_flag(mocker, app, session, test_name, flag_enabled, - permission_error, expected_code, expected_msg): - """Test validate_permission_and_completing_party is called when enabled-deeper-permission-action flag is enabled.""" +def test_incorporation_permission_and_completing_party(mocker, app, session, test_name, + permission_error, expected_code, expected_msg): + """Test validate_permission_and_completing_party is always called.""" account_id = '123456' filing_json = _build_incorporation_filing_json() _setup_incorporation_permission_mocks(mocker, filing_json, Business.LegalTypes.COOP.value) - mocker.patch.object(flags, 'is_on', return_value=flag_enabled) mock_validate_permission = mocker.patch.object(incorporation_application, 'validate_permission_and_completing_party', return_value=permission_error) with app.test_request_context(headers={'account-id': account_id}): err = validate(None, filing_json, account_id) - if flag_enabled: - mock_validate_permission.assert_called_once() - call_args = mock_validate_permission.call_args - assert call_args[0][0] is None - assert call_args[0][1] == filing_json - assert call_args[0][2] == incorporation_application_name - check_options = call_args[0][4] - - assert check_options.get('check_name') is False - assert check_options.get('check_email') is True - assert check_options.get('check_address') is False - assert check_options.get('check_document_email') is True - else: - # When flag is off - mock_validate_permission.assert_not_called() + mock_validate_permission.assert_called_once() + call_args = mock_validate_permission.call_args + assert call_args[0][0] is None + assert call_args[0][1] == filing_json + assert call_args[0][2] == incorporation_application_name + check_options = call_args[0][4] + + assert check_options.get('check_name') is False + assert check_options.get('check_email') is True + assert check_options.get('check_address') is False + assert check_options.get('check_document_email') is True if expected_code: assert err is not None assert err.code == expected_code diff --git a/legal-api/tests/unit/services/filings/validations/test_notice_of_withdrawal.py b/legal-api/tests/unit/services/filings/validations/test_notice_of_withdrawal.py index dd2c7c1313..b2b737f02c 100644 --- a/legal-api/tests/unit/services/filings/validations/test_notice_of_withdrawal.py +++ b/legal-api/tests/unit/services/filings/validations/test_notice_of_withdrawal.py @@ -29,6 +29,8 @@ from registry_schemas.example_data import FILING_HEADER, NOTICE_OF_WITHDRAWAL, DISSOLUTION, INCORPORATION +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + # setup FILING_HAS_POA_IN_EFFECT = {'error': 'Cannot file a Notice of Withdrawal as the filing has a POA in effect.'} diff --git a/legal-api/tests/unit/services/filings/validations/test_put_back_off.py b/legal-api/tests/unit/services/filings/validations/test_put_back_off.py index 077015833a..fa52c9503a 100644 --- a/legal-api/tests/unit/services/filings/validations/test_put_back_off.py +++ b/legal-api/tests/unit/services/filings/validations/test_put_back_off.py @@ -13,6 +13,7 @@ # limitations under the License. """Test Put back off validations.""" import copy +import pytest from registry_schemas.example_data import PUT_BACK_OFF, FILING_HEADER @@ -20,6 +21,8 @@ from tests.unit.models import factory_business +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + def test_put_back_off(session, monkeypatch): """Assert valid put back off.""" diff --git a/legal-api/tests/unit/services/filings/validations/test_registration.py b/legal-api/tests/unit/services/filings/validations/test_registration.py index 882f403596..8e5a7479a5 100644 --- a/legal-api/tests/unit/services/filings/validations/test_registration.py +++ b/legal-api/tests/unit/services/filings/validations/test_registration.py @@ -30,6 +30,8 @@ from tests.unit.services.filings.validations import create_party, create_party_address from tests.unit.services.utils import jwt_request_context +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + now = datetime.now().strftime('%Y-%m-%d') GP_REGISTRATION = copy.deepcopy(FILING_HEADER) @@ -356,7 +358,8 @@ def test_invalid_business_address(app, session, jwt, test_name, filing): ('general_user_greater', 'general', [BASIC_USER], timedelta(days=90), True), ('general_user_invalid_greater', 'general', [BASIC_USER], timedelta(days=91), False), ('general_user_lesser', 'general', [BASIC_USER], relativedelta(years=-10), True), - ('general_user_invalid_lesser', 'general', [BASIC_USER], relativedelta(years=-10, days=-1), False) + ('general_user_lesser_over_limit_with_permission', 'general', [BASIC_USER], + relativedelta(years=-10, days=-1), True) ] ) def test_validate_start_date(app, session, jwt, test_name, username, roles, delta_date, is_valid): diff --git a/legal-api/tests/unit/services/filings/validations/test_restoration.py b/legal-api/tests/unit/services/filings/validations/test_restoration.py index e0deb8f51d..34dee9f783 100644 --- a/legal-api/tests/unit/services/filings/validations/test_restoration.py +++ b/legal-api/tests/unit/services/filings/validations/test_restoration.py @@ -25,6 +25,8 @@ from legal_api.services.filings.validations.validation import validate from registry_schemas.example_data import RESTORATION, get_filing_template +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + TEST_IDENTIFIER = 'BC1234567' diff --git a/legal-api/tests/unit/services/filings/validations/test_review_imported_data.py b/legal-api/tests/unit/services/filings/validations/test_review_imported_data.py index a9b608d7bd..f5a16474ad 100644 --- a/legal-api/tests/unit/services/filings/validations/test_review_imported_data.py +++ b/legal-api/tests/unit/services/filings/validations/test_review_imported_data.py @@ -25,6 +25,8 @@ from registry_schemas.example_data import FILING_HEADER from tests.unit.models import factory_business, factory_party_role +pytestmark = pytest.mark.usefixtures("authorized_filing_validation_user") + VALID_ADDRESS = { 'streetAddress': '123 A St',