Skip to content

Commit 1936c8e

Browse files
committed
No export buttons on saved dashboards, closes #71
1 parent 2cb18a7 commit 1936c8e

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from django.contrib.auth.models import Permission
3+
from django_sql_dashboard.models import Dashboard
34

45

56
@pytest.fixture
@@ -16,3 +17,11 @@ def execute_sql_permission():
1617
content_type__model="dashboard",
1718
codename="execute_sql",
1819
)
20+
21+
@pytest.fixture
22+
def saved_dashboard(dashboard_db):
23+
dashboard = Dashboard.objects.create(
24+
slug="test", title="Test dashboard", view_policy="public"
25+
)
26+
dashboard.queries.create(sql="select 11 + 33")
27+
dashboard.queries.create(sql="select 22 + 55")

django_sql_dashboard/templates/django_sql_dashboard/widgets/default.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{% if result.truncated %}
1414
<p class="results-truncated">
1515
Results were truncated
16-
{% if user_can_export_data %}
16+
{% if user_can_export_data and not saved_dashboard %}
1717
<input
1818
class="btn"
1919
style="font-size: 0.6rem"
@@ -56,7 +56,7 @@
5656
</table>
5757
<details style="margin-top: 1em;"><summary style="font-size: 0.7em; margin-bottom: 0.5em; cursor: pointer;">Copy and export data</summary>
5858
<textarea id="copyable-{{ result.index }}" style="height: 10em">{{ result|sql_dashboard_tsv }}</textarea>
59-
{% if user_can_export_data %}
59+
{% if user_can_export_data and not saved_dashboard %}
6060
<div class="export-buttons">
6161
<input
6262
class="btn"

test_project/test_dashboard.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@
44
from bs4 import BeautifulSoup
55
from django.core import signing
66

7-
from django_sql_dashboard.models import Dashboard
87
from django_sql_dashboard.utils import SQL_SALT, is_valid_base64_json, sign_sql
98

109

11-
@pytest.fixture
12-
def saved_dashboard(dashboard_db):
13-
dashboard = Dashboard.objects.create(
14-
slug="test", title="Test dashboard", view_policy="public"
15-
)
16-
dashboard.queries.create(sql="select 11 + 33")
17-
dashboard.queries.create(sql="select 22 + 55")
18-
19-
2010
def test_dashboard_submit_sql(admin_client, dashboard_db):
2111
# Test full flow of POST submitting new SQL, having it signed
2212
# and having it redirect to the results page

test_project/test_export.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ def test_export_requires_setting(admin_client, dashboard_db):
1010
assert response.status_code == 403
1111

1212

13+
def test_no_export_on_saved_dashboard(admin_client, dashboard_db, settings, saved_dashboard):
14+
settings.DASHBOARD_ENABLE_FULL_EXPORT = True
15+
response = admin_client.get("/dashboard/test/")
16+
assert response.status_code == 200
17+
assert b'<pre class="sql">select 22 + 55</pre>' in response.content
18+
assert b'Export all as CSV' not in response.content
19+
20+
1321
def test_export_csv(admin_client, dashboard_db, settings):
1422
settings.DASHBOARD_ENABLE_FULL_EXPORT = True
1523
response = admin_client.post(

0 commit comments

Comments
 (0)