From f18287d3b8856be44d9cc8c9585b769f787d57ea Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 9 Nov 2026 13:54:28 +0300 Subject: [PATCH] fix(instances): the delete page names the host only where hosts are shown The confirmation page put "on " in its heading for every owner who may delete the VM, while the VM list and page show the host only to superusers and users with view_instances. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea --- .../templates/instances/destroy_instance_form.html | 2 +- instances/tests/test_destroy.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/instances/templates/instances/destroy_instance_form.html b/instances/templates/instances/destroy_instance_form.html index 252ae1ad..aeba366a 100644 --- a/instances/templates/instances/destroy_instance_form.html +++ b/instances/templates/instances/destroy_instance_form.html @@ -4,7 +4,7 @@ {% block title %}{% blocktrans with name=instance.name %}Destroy {{ name }}{% endblocktrans %}{% endblock title %} {% block page_heading %} -{% blocktrans with name=instance.name %}Destroy {{ name }}{% endblocktrans %} {% blocktrans with host=instance.compute.name %}on {{ host }}{% endblocktrans %} +{% blocktrans with name=instance.name %}Destroy {{ name }}{% endblocktrans %}{% if perms.instances.view_instances %} {% blocktrans with host=instance.compute.name %}on {{ host }}{% endblocktrans %}{% endif %} {% endblock page_heading %} {% block content %} diff --git a/instances/tests/test_destroy.py b/instances/tests/test_destroy.py index 54adb4aa..8e9ce166 100644 --- a/instances/tests/test_destroy.py +++ b/instances/tests/test_destroy.py @@ -236,6 +236,16 @@ class DestroyOrderTestCase(TransactionTestCase): response = self.client.get(reverse("instances:destroy", args=[self.instance.id])) self.assertEqual(b"Its TPM state is deleted" in response.content, shown) + def test_the_confirmation_page_names_the_host_only_to_whom_the_app_shows_hosts(self): + owner = get_user_model().objects.create_user("destroy_owner", password="pw") + self.instance.userinstance_set.create(user=owner, is_delete=True) + for user, shown in ((self.admin, True), (owner, False)): + with self.subTest(user=user.username), patch("instances.models.wvmInstance"): + self.client.force_login(user) + response = self.client.get(reverse("instances:destroy", args=[self.instance.id])) + self.assertEqual(response.status_code, 200) + self.assertEqual("on destroy-compute" in response.content.decode(), shown) + def test_the_confirmation_page_of_a_paused_vm_offers_the_form(self): with patch("instances.models.wvmInstance") as wvm: wvm.return_value.get_status.return_value = 3 # paused