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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
validate_signing_date,
)
from legal_api.services.permissions import ListActionsPermissionsAllowed, PermissionService
from legal_api.services.request_context import get_request_context
from legal_api.services.utils import get_date, get_str
from legal_api.utils.auth import jwt

Expand Down Expand Up @@ -90,7 +91,10 @@ def validate(amalgamation_json: dict, account_id) -> Error | None:
return msg # Cannot continue validation without legal_type

# (flags.value is None when the flag client is unavailable - treat as nothing enabled)
enabled_legal_types = (flags.value("supported-amalgamation-entities") or "").split()
request_context = get_request_context()
enabled_legal_types = (flags.value("supported-amalgamation-entities",
request_context.user,
request_context.account_id) or "").split()
if legal_type not in enabled_legal_types:
return Error(HTTPStatus.FORBIDDEN,
[{"error": babel(f"{legal_type} is not enabled for amalgamation entities.")}])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2951,4 +2951,19 @@ def test_amalgamation_entity_not_enabled(mocker, app, session, jwt, flag_value):

assert err.code == HTTPStatus.FORBIDDEN
assert err.msg[0]['error'] == 'CP is not enabled for amalgamation entities.'



def test_amalgamation_entity_flag_targets_user_and_account(mocker, app, session, jwt):
"""Assert the enabled-entities flag is evaluated for the request's user and account."""
account_id = '123456'
filing = _get_coop_amalg_template()
_setup_coop_amalgamation_mocks(mocker)
flag_mock = mocker.patch.object(flags, 'value', return_value='BC')

with jwt_request_context(app, jwt, [STAFF_ROLE], 'staff-user', account_id):
err = validate(None, filing, account_id)

assert err.code == HTTPStatus.FORBIDDEN
flag_args = next(c.args for c in flag_mock.call_args_list if c.args[0] == 'supported-amalgamation-entities')
assert flag_args[1].username == 'staff-user'
assert flag_args[2] == account_id