Skip to content
Open
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
2 changes: 0 additions & 2 deletions legal-api/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
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.84"
version = "3.1.85"
description = ""
authors = [
{name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"}
Expand Down
5 changes: 1 addition & 4 deletions legal-api/src/legal_api/resources/v2/business/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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."
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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", []):
Expand Down Expand Up @@ -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})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ 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)
if error:
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
Expand Down
45 changes: 45 additions & 0 deletions legal-api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand Down
Loading