mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix bug with breadcrumbs and request=None, closes #1849
This commit is contained in:
parent
c7dd76c262
commit
df7bf0b2fc
2 changed files with 15 additions and 3 deletions
|
|
@ -633,15 +633,18 @@ class Datasette:
|
|||
|
||||
async def _crumb_items(self, request, table=None, database=None):
|
||||
crumbs = []
|
||||
actor = None
|
||||
if request:
|
||||
actor = request.actor
|
||||
# Top-level link
|
||||
if await self.permission_allowed(
|
||||
actor=request.actor, action="view-instance", default=True
|
||||
actor=actor, action="view-instance", default=True
|
||||
):
|
||||
crumbs.append({"href": self.urls.instance(), "label": "home"})
|
||||
# Database link
|
||||
if database:
|
||||
if await self.permission_allowed(
|
||||
actor=request.actor,
|
||||
actor=actor,
|
||||
action="view-database",
|
||||
resource=database,
|
||||
default=True,
|
||||
|
|
@ -656,7 +659,7 @@ class Datasette:
|
|||
if table:
|
||||
assert database, "table= requires database="
|
||||
if await self.permission_allowed(
|
||||
actor=request.actor,
|
||||
actor=actor,
|
||||
action="view-table",
|
||||
resource=(database, table),
|
||||
default=True,
|
||||
|
|
|
|||
|
|
@ -125,3 +125,12 @@ async def test_datasette_ensure_permissions_check_visibility(
|
|||
visible, private = await ds.check_visibility(actor, permissions=permissions)
|
||||
assert visible == should_allow
|
||||
assert private == expected_private
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_datasette_render_template_no_request():
|
||||
# https://github.com/simonw/datasette/issues/1849
|
||||
ds = Datasette([], memory=True)
|
||||
await ds.invoke_startup()
|
||||
rendered = await ds.render_template("error.html")
|
||||
assert "Error " in rendered
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue