Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable deleting of default dashboard #3233

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3150.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable deletion of the default dashboard
4 changes: 4 additions & 0 deletions python/nav/web/webfront/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ def delete_dashboard(request, did):
return HttpResponseBadRequest('Cannot delete last dashboard')

dash = get_object_or_404(AccountDashboard, pk=did, account=request.account)

if dash.is_default:
return HttpResponseBadRequest('Cannot delete default dashboard')

dash.delete()

return HttpResponse('Dashboard deleted')
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/web/webfront_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ def test_delete_last_dashboard_should_fail(db, client, admin_account):
assert AccountDashboard.objects.filter(id=dashboard.id).exists()


def test_delete_default_dashboard_should_fail(db, client, admin_account):
"""Tests that the default dashboard cannot be deleted"""
# Creating another dashboard, so that default is not the last one
AccountDashboard.objects.create(
name="non_default",
is_default=False,
account=admin_account,
)

default_dashboard = AccountDashboard.objects.get(
is_default=True,
account=admin_account,
)
url = reverse("delete-dashboard", args=(default_dashboard.pk,))
response = client.post(url, follow=True)

assert response.status_code == 400
assert "Cannot delete default dashboard" in smart_str(response.content)
assert AccountDashboard.objects.filter(id=default_dashboard.id).exists()


def test_when_logging_in_it_should_change_the_session_id(
db, client, admin_username, admin_password
):
Expand Down
Loading