mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
1a861be19e
commit
18a64fbb29
12 changed files with 193 additions and 13 deletions
|
|
@ -43,6 +43,7 @@ EXPECTED_PLUGINS = [
|
|||
"extra_js_urls",
|
||||
"extra_template_vars",
|
||||
"forbidden",
|
||||
"menu_links",
|
||||
"permission_allowed",
|
||||
"prepare_connection",
|
||||
"prepare_jinja2_environment",
|
||||
|
|
@ -64,6 +65,7 @@ EXPECTED_PLUGINS = [
|
|||
"canned_queries",
|
||||
"extra_js_urls",
|
||||
"extra_template_vars",
|
||||
"menu_links",
|
||||
"permission_allowed",
|
||||
"render_cell",
|
||||
"startup",
|
||||
|
|
|
|||
|
|
@ -290,3 +290,9 @@ def forbidden(datasette, request, message):
|
|||
datasette._last_forbidden_message = message
|
||||
if request.path == "/data2":
|
||||
return Response.redirect("/login?message=" + message)
|
||||
|
||||
|
||||
@hookimpl
|
||||
def menu_links(datasette, actor):
|
||||
if actor:
|
||||
return [{"href": datasette.urls.instance(), "label": "Hello"}]
|
||||
|
|
|
|||
|
|
@ -146,3 +146,12 @@ def canned_queries(datasette, database):
|
|||
}
|
||||
|
||||
return inner
|
||||
|
||||
|
||||
@hookimpl(trylast=True)
|
||||
def menu_links(datasette, actor):
|
||||
async def inner():
|
||||
if actor:
|
||||
return [{"href": datasette.urls.instance(), "label": "Hello 2"}]
|
||||
|
||||
return inner
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ def test_logout_button_in_navigation(app_client, path):
|
|||
)
|
||||
anon_response = app_client.get(path)
|
||||
for fragment in (
|
||||
"<strong>test</strong> ·",
|
||||
"<strong>test</strong>",
|
||||
'<form action="/-/logout" method="post">',
|
||||
):
|
||||
assert fragment in response.text
|
||||
|
|
@ -112,5 +112,4 @@ def test_logout_button_in_navigation(app_client, path):
|
|||
def test_no_logout_button_in_navigation_if_no_ds_actor_cookie(app_client, path):
|
||||
response = app_client.get(path + "?_bot=1")
|
||||
assert "<strong>bot</strong>" in response.text
|
||||
assert "<strong>bot</strong> ·" not in response.text
|
||||
assert '<form action="/-/logout" method="post">' not in response.text
|
||||
|
|
|
|||
|
|
@ -765,3 +765,20 @@ def test_hook_forbidden(restore_working_directory):
|
|||
assert 302 == response2.status
|
||||
assert "/login?message=view-database" == response2.headers["Location"]
|
||||
assert "view-database" == client.ds._last_forbidden_message
|
||||
|
||||
|
||||
def test_hook_menu_links(app_client):
|
||||
def get_menu_links(html):
|
||||
soup = Soup(html, "html.parser")
|
||||
return [
|
||||
{"label": a.text, "href": a["href"]} for a in soup.find("nav").select("a")
|
||||
]
|
||||
|
||||
response = app_client.get("/")
|
||||
assert get_menu_links(response.text) == []
|
||||
|
||||
response_2 = app_client.get("/?_bot=1")
|
||||
assert get_menu_links(response_2.text) == [
|
||||
{"label": "Hello", "href": "/"},
|
||||
{"label": "Hello 2", "href": "/"},
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue