Skip to content

Commit

Permalink
Disable deleting of default dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Nov 25, 2024
1 parent 6b1b864 commit 6c55c5a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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

0 comments on commit 6c55c5a

Please sign in to comment.