mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
8bc9b1ee03
commit
a508fc4a8e
4 changed files with 10 additions and 76 deletions
|
|
@ -469,7 +469,7 @@ def register_actions(datasette):
|
|||
description="View a collection",
|
||||
resource_class=DatabaseResource,
|
||||
),
|
||||
# Test actions for test_hook_permission_allowed (global actions - no resource_class)
|
||||
# Test actions for test_hook_custom_allowed (global actions - no resource_class)
|
||||
Action(
|
||||
name="this_is_allowed",
|
||||
abbr=None,
|
||||
|
|
@ -553,7 +553,7 @@ def register_actions(datasette):
|
|||
def permission_resources_sql(datasette, actor, action):
|
||||
from datasette.permissions import PermissionSQL
|
||||
|
||||
# Handle test actions used in test_hook_permission_allowed
|
||||
# Handle test actions used in test_hook_custom_allowed
|
||||
if action == "this_is_allowed":
|
||||
return PermissionSQL.allow(reason="test plugin allows this_is_allowed")
|
||||
elif action == "this_is_denied":
|
||||
|
|
|
|||
|
|
@ -935,7 +935,7 @@ async def test_edit_sql_link_on_canned_queries(ds_client, path, expected):
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"permission_allowed",
|
||||
"has_permission",
|
||||
[
|
||||
pytest.param(
|
||||
True,
|
||||
|
|
@ -943,15 +943,15 @@ async def test_edit_sql_link_on_canned_queries(ds_client, path, expected):
|
|||
False,
|
||||
],
|
||||
)
|
||||
def test_edit_sql_link_not_shown_if_user_lacks_permission(permission_allowed):
|
||||
def test_edit_sql_link_not_shown_if_user_lacks_permission(has_permission):
|
||||
with make_app_client(
|
||||
config={
|
||||
"allow_sql": None if permission_allowed else {"id": "not-you"},
|
||||
"allow_sql": None if has_permission else {"id": "not-you"},
|
||||
"databases": {"fixtures": {"queries": {"simple": "select 1 + 1"}}},
|
||||
}
|
||||
) as client:
|
||||
response = client.get("/fixtures/simple")
|
||||
if permission_allowed:
|
||||
if has_permission:
|
||||
assert "Edit SQL" in response.text
|
||||
else:
|
||||
assert "Edit SQL" not in response.text
|
||||
|
|
|
|||
|
|
@ -677,7 +677,7 @@ async def test_existing_scope_actor_respected(ds_client):
|
|||
("this_is_denied_async", False),
|
||||
],
|
||||
)
|
||||
async def test_hook_permission_allowed(action, expected):
|
||||
async def test_hook_custom_allowed(action, expected):
|
||||
# Test actions and permission logic are defined in tests/plugins/my_plugin.py
|
||||
ds = Datasette(plugins_dir=PLUGINS_DIR)
|
||||
await ds.invoke_startup()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue