diff --git a/changelog.d/3150.fixed.md b/changelog.d/3150.fixed.md new file mode 100644 index 0000000000..d31c6e399d --- /dev/null +++ b/changelog.d/3150.fixed.md @@ -0,0 +1 @@ +Disable deletion of the default dashboard diff --git a/python/nav/web/webfront/views.py b/python/nav/web/webfront/views.py index 85bdb88be5..adb4307290 100644 --- a/python/nav/web/webfront/views.py +++ b/python/nav/web/webfront/views.py @@ -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') diff --git a/tests/integration/web/webfront_test.py b/tests/integration/web/webfront_test.py index c4118ae017..d07f68be11 100644 --- a/tests/integration/web/webfront_test.py +++ b/tests/integration/web/webfront_test.py @@ -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 ):