1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(tags): second audit: unchanged saves, report, other lists, hosts list

- Saving a VM's tags unchanged writes no audit row.
- The VM report has a Tags column.
- A host's VM list and a user's VMs (account page) show the VMs' tags.
- The hosts list says "No host matches the filters." with Clear the
  filters, as the VM list does; the tag list keeps to a phone's width
  with a long tag.
- A removed VM's delete page says its owners and tags no longer come
  back; the VM history rows say "owners and tags kept/restored".
- The API's ?tag= is trimmed; Tom Select's "Add tag" line shows the name
  in lower case as it is made; Bulk Migrate's tag list goes back to its
  title after a choice, so the same tag can be chosen again.
This commit is contained in:
catborise 2026-11-18 23:15:34 +03:00
parent 45225df1a4
commit b74e798e70
23 changed files with 376 additions and 324 deletions

View file

@ -44,14 +44,17 @@ vm.runInNewContext(SCRIPT, vm.createContext({document: {
}}));
const ticked = () => boxes.filter((b) => b.checked).map((b) => b.name);
const seen = [], counts = [[counter.textContent, button.disabled]];
let tagChoice;
for (const [id, checked, value] of STEPS) {
const target = {id, checked, value, form: choose};
if (id === "bulk-migrate-tag") tagChoice = target;
handlers[id]?.({target});
handlers.document({target}); // the change bubbles to the page
seen.push(ticked());
if (tagChoice === target) tagChoice = target.value;
counts.push([counter.textContent, button.disabled]);
}
console.log(JSON.stringify({seen, submitted, counts, shownRemoved}));
console.log(JSON.stringify({seen, submitted, counts, shownRemoved, tagChoice}));
"""
@ -77,6 +80,7 @@ class BulkMigrateScriptTests(unittest.TestCase):
result = self.run_script([["bulk-migrate-tag", False, "prod"], ["bulk-migrate-tag", False, ""],
["bulk-migrate-tag", False, "web"]])
self.assertEqual(result["seen"], [["off"], ["off"], ["run", "off"]]) # "": the ticks stay
self.assertEqual(result["tagChoice"], "", "the list goes back to its title: the same tag can be chosen again")
def test_the_button_counts_the_ticked_vms_and_is_off_without_one(self):
self.assertEqual(self.run_script([["bulk-migrate-all", False], ["bulk-migrate-all", True]])["counts"],

View file

@ -59,14 +59,14 @@ class OwnershipTestCase(TestCase):
self.assertEqual(self.ownership(self.host_a), (True, [(self.owner, True, False, True)]))
self.assertFalse(InstanceTombstone.objects.exists())
self.assertEqual(self.rows(), [
("-", "host-a", f"VM vm ({UUID}): owners kept on the Removed VMs page"),
("-", "host-a", f"VM vm ({UUID}): owners restored"),
("-", "host-a", f"VM vm ({UUID}): owners and tags kept on the Removed VMs page"),
("-", "host-a", f"VM vm ({UUID}): owners and tags restored"),
])
def test_an_ownerless_vm_leaves_a_row(self):
Instance.objects.create(compute=self.host_a, name="vm", uuid=UUID)
refresh_instance_database(self.host_a)
self.assertEqual(self.rows(), [("-", "host-a", f"VM vm ({UUID}): left the panel (no owners)")])
self.assertEqual(self.rows(), [("-", "host-a", f"VM vm ({UUID}): left the panel (no owners or tags)")])
def test_move_seen_on_the_new_host_first(self):
self.owned_vm(self.host_a)
@ -164,7 +164,7 @@ class OwnershipTestCase(TestCase):
self.assertEqual((tombstone.owners[0]["user"], tombstone.host), (self.owner.id, "host-a"))
self.assertEqual(self.rows(), [
("cd-admin", "-", "Login"),
("-", "host-a", f"VM vm ({UUID}): owners kept on the Removed VMs page"),
("-", "host-a", f"VM vm ({UUID}): owners and tags kept on the Removed VMs page"),
("cd-admin", "host-a", "Compute host-a (host-a.example): delete"),
])

View file

@ -108,4 +108,7 @@ class HostTagsTests(TestCase):
self.assertContains(response, "rack-1")
self.assertContains(response, '<option value="rack-1">rack-1 (1)</option>', html=True)
self.assertContains(response, 'data-tag-filter="rack-1"')
# a search and a tag that match no host: the page says so and clears them
self.assertContains(response, 'id="no-match"')
self.assertContains(response, 'id="clear-filters"')
self.assertContains(response, 'data-tags="rack-1"')