Show padlock on private index page, refs #811

This commit is contained in:
Simon Willison 2020-06-08 07:18:37 -07:00
commit 1cf86e5ecc
3 changed files with 10 additions and 1 deletions

View file

@ -5,7 +5,7 @@
{% block body_class %}index{% endblock %} {% block body_class %}index{% endblock %}
{% block content %} {% block content %}
<h1>{{ metadata.title or "Datasette" }}</h1> <h1>{{ metadata.title or "Datasette" }}{% if private %} 🔒{% endif %}</h1>
{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %} {% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %}

View file

@ -121,5 +121,8 @@ class IndexView(BaseView):
"databases": databases, "databases": databases,
"metadata": self.ds.metadata(), "metadata": self.ds.metadata(),
"datasette_version": __version__, "datasette_version": __version__,
"private": not await self.ds.permission_allowed(
None, "view-instance"
),
}, },
) )

View file

@ -16,10 +16,16 @@ def test_view_instance(allow, expected_anon, expected_auth):
): ):
anon_response = client.get(path) anon_response = client.get(path)
assert expected_anon == anon_response.status assert expected_anon == anon_response.status
if allow and path == "/" and anon_response.status == 200:
# Should be no padlock
assert "<h1>Datasette 🔒</h1>" not in anon_response.text
auth_response = client.get( auth_response = client.get(
path, cookies={"ds_actor": client.ds.sign({"id": "root"}, "actor")}, path, cookies={"ds_actor": client.ds.sign({"id": "root"}, "actor")},
) )
assert expected_auth == auth_response.status assert expected_auth == auth_response.status
# Check for the padlock
if allow and path == "/" and expected_anon == 403 and expected_auth == 200:
assert "<h1>Datasette 🔒</h1>" in auth_response.text
@pytest.mark.parametrize( @pytest.mark.parametrize(