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):
|
async def _crumb_items(self, request, table=None, database=None):
|
||||||
crumbs = []
|
crumbs = []
|
||||||
|
actor = None
|
||||||
|
if request:
|
||||||
|
actor = request.actor
|
||||||
# Top-level link
|
# Top-level link
|
||||||
if await self.permission_allowed(
|
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"})
|
crumbs.append({"href": self.urls.instance(), "label": "home"})
|
||||||
# Database link
|
# Database link
|
||||||
if database:
|
if database:
|
||||||
if await self.permission_allowed(
|
if await self.permission_allowed(
|
||||||
actor=request.actor,
|
actor=actor,
|
||||||
action="view-database",
|
action="view-database",
|
||||||
resource=database,
|
resource=database,
|
||||||
default=True,
|
default=True,
|
||||||
|
|
@ -656,7 +659,7 @@ class Datasette:
|
||||||
if table:
|
if table:
|
||||||
assert database, "table= requires database="
|
assert database, "table= requires database="
|
||||||
if await self.permission_allowed(
|
if await self.permission_allowed(
|
||||||
actor=request.actor,
|
actor=actor,
|
||||||
action="view-table",
|
action="view-table",
|
||||||
resource=(database, table),
|
resource=(database, table),
|
||||||
default=True,
|
default=True,
|
||||||
|
|
|
||||||
|
|
@ -125,3 +125,12 @@ async def test_datasette_ensure_permissions_check_visibility(
|
||||||
visible, private = await ds.check_visibility(actor, permissions=permissions)
|
visible, private = await ds.check_visibility(actor, permissions=permissions)
|
||||||
assert visible == should_allow
|
assert visible == should_allow
|
||||||
assert private == expected_private
|
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