Accept numeric permission booleans

This commit is contained in:
Simon Willison 2026-07-13 23:21:31 -07:00
commit c81d001d0c
2 changed files with 18 additions and 0 deletions

View file

@ -96,6 +96,10 @@ class ConfigPermissionProcessor:
"""Evaluate an allow block against the current actor."""
if allow_block is None:
return None
# Values passed using ``-s permissions.* 1`` or ``0`` are parsed as
# integers, but should retain the CLI's boolean 1/0 behavior.
if isinstance(allow_block, int) and allow_block in (0, 1):
return bool(allow_block)
return actor_matches_allow(self.actor, allow_block)
def is_in_restriction_allowlist(

View file

@ -457,6 +457,20 @@ async def test_permissions_debug(ds_client, filter_):
assert checks == expected_checks
@pytest.mark.asyncio
@pytest.mark.parametrize(
"permissions_debug,expected_status",
(
(1, 200),
(0, 403),
),
)
async def test_permissions_debug_numeric_boolean(permissions_debug, expected_status):
ds = Datasette(config={"permissions": {"permissions-debug": permissions_debug}})
response = await ds.client.get("/-/permissions")
assert response.status_code == expected_status
@pytest.mark.asyncio
@pytest.mark.parametrize(
"actor,allow,expected_fragment",