Skip to content

Commit 4288614

Browse files
committed
Don't show Dashboard index link to users without permission, closes #87
1 parent 8046099 commit 4288614

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

django_sql_dashboard/templates/django_sql_dashboard/saved_dashboard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{% endblock %}
1212

1313
{% block content %}
14-
<p><a href="/dashboard/">Dashboard index</a></p>
14+
{% if user_can_execute_sql %}<p><a href="/dashboard/">Dashboard index</a></p>{% endif %}
1515
<h1>{% if dashboard.title %}{{ dashboard.title }}{% else %}{{ dashboard.slug }}{% endif %}</h1>
1616
{% if dashboard.description %}
1717
<p>{{ dashboard.description }}</p>

test_project/test_dashboard_permissions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,13 @@ def test_superuser_can_reassign_ownership(client, db):
340340
user.save()
341341
response2 = client.get(dashboard.get_edit_url())
342342
assert b'<input type="text" name="owned_by" value="' in response2.content
343+
344+
345+
def test_no_link_to_index_on_saved_dashboard_for_logged_out_user(client, db):
346+
dashboard = Dashboard.objects.create(
347+
slug="dashboard",
348+
owned_by=User.objects.create(username="test", is_staff=True),
349+
view_policy="public",
350+
)
351+
response = client.get(dashboard.get_absolute_url())
352+
assert b'<a href="/dashboard/">' not in response.content

0 commit comments

Comments
 (0)