mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
view_actions plugin hook, closes #2297
This commit is contained in:
parent
daf5ca02ca
commit
909c85cd2b
7 changed files with 85 additions and 21 deletions
|
|
@ -56,6 +56,7 @@ EXPECTED_PLUGINS = [
|
|||
"skip_csrf",
|
||||
"startup",
|
||||
"table_actions",
|
||||
"view_actions",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -391,6 +391,18 @@ def table_actions(datasette, database, table, actor):
|
|||
]
|
||||
|
||||
|
||||
@hookimpl
|
||||
def view_actions(datasette, database, view, actor):
|
||||
if actor:
|
||||
return [
|
||||
{
|
||||
"href": datasette.urls.instance(),
|
||||
"label": f"Database: {database}",
|
||||
},
|
||||
{"href": datasette.urls.instance(), "label": f"View: {view}"},
|
||||
]
|
||||
|
||||
|
||||
@hookimpl
|
||||
def query_actions(datasette, database, query_name, sql):
|
||||
# Don't explain an explain
|
||||
|
|
|
|||
|
|
@ -923,18 +923,34 @@ async def test_hook_menu_links(ds_client):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("table_or_view", ["facetable", "simple_view"])
|
||||
async def test_hook_table_actions(ds_client, table_or_view):
|
||||
response = await ds_client.get(f"/fixtures/{table_or_view}")
|
||||
async def test_hook_table_actions(ds_client):
|
||||
response = await ds_client.get("/fixtures/facetable")
|
||||
assert get_actions_links(response.text) == []
|
||||
|
||||
response_2 = await ds_client.get(f"/fixtures/{table_or_view}?_bot=1&_hello=BOB")
|
||||
response_2 = await ds_client.get("/fixtures/facetable?_bot=1&_hello=BOB")
|
||||
assert sorted(
|
||||
get_actions_links(response_2.text), key=lambda link: link["label"]
|
||||
) == [
|
||||
{"label": "Database: fixtures", "href": "/", "description": None},
|
||||
{"label": "From async BOB", "href": "/", "description": None},
|
||||
{"label": f"Table: {table_or_view}", "href": "/", "description": None},
|
||||
{"label": "Table: facetable", "href": "/", "description": None},
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hook_view_actions(ds_client):
|
||||
response = await ds_client.get("/fixtures/simple_view")
|
||||
assert get_actions_links(response.text) == []
|
||||
|
||||
response_2 = await ds_client.get(
|
||||
"/fixtures/simple_view",
|
||||
cookies={"ds_actor": ds_client.actor_cookie({"id": "bob"})},
|
||||
)
|
||||
assert sorted(
|
||||
get_actions_links(response_2.text), key=lambda link: link["label"]
|
||||
) == [
|
||||
{"label": "Database: fixtures", "href": "/", "description": None},
|
||||
{"label": "View: simple_view", "href": "/", "description": None},
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue