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:
parent
45225df1a4
commit
b74e798e70
23 changed files with 376 additions and 324 deletions
|
|
@ -14,7 +14,7 @@ TAG_PARAMETER = OpenApiParameter("tag", str, description="Only those with this t
|
|||
|
||||
def with_tag(queryset, request):
|
||||
"""queryset's VMs or hosts with the ?tag= of request, all without one; their tags read at once."""
|
||||
tag = request.query_params.get("tag", "").lower() # the names are kept in lower case
|
||||
tag = request.query_params.get("tag", "").strip().lower() # the names are kept in lower case
|
||||
return (queryset.filter(tags__name=tag) if tag else queryset).prefetch_related("tags")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@
|
|||
<a class="link-primary" href="{% url 'instances:instance' instance.id %}">{{ instance.name }}</a>
|
||||
<br>
|
||||
{% if instance.info %}<p class="m-0 small fst-italic">{{ instance.title }}</p>{% endif %}
|
||||
{% include 'common/tag_badges.html' with tags=instance.tags.all %}
|
||||
</td>
|
||||
<td>
|
||||
<em>
|
||||
|
|
|
|||
|
|
@ -121,6 +121,11 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{# table_filter.js shows it while no host matches #}
|
||||
<div id="no-match" class="text-center text-body-secondary py-4" hidden>
|
||||
{% trans "No host matches the filters." %}
|
||||
<button type="button" class="btn btn-link" id="clear-filters">{% trans "Clear the filters" %}</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -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"')
|
||||
|
|
|
|||
|
|
@ -135,9 +135,9 @@ def _bury(inst):
|
|||
if owners or inst.is_template or tags:
|
||||
InstanceTombstone.objects.create(uuid=inst.uuid, name=inst.name, host=inst.compute.name,
|
||||
is_template=inst.is_template, owners=owners, tags=tags)
|
||||
_log(inst, "owners kept on the Removed VMs page")
|
||||
_log(inst, "owners and tags kept on the Removed VMs page")
|
||||
else:
|
||||
_log(inst, "left the panel (no owners)")
|
||||
_log(inst, "left the panel (no owners or tags)")
|
||||
|
||||
|
||||
def _restore(inst):
|
||||
|
|
@ -159,7 +159,7 @@ def _restore(inst):
|
|||
inst.is_template = True
|
||||
inst.save(update_fields=["is_template"])
|
||||
InstanceTombstone.objects.filter(uuid=inst.uuid).delete()
|
||||
_log(inst, "owners restored")
|
||||
_log(inst, "owners and tags restored")
|
||||
|
||||
|
||||
def _host_domains(compute):
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ def instances(request, compute_id):
|
|||
# read first: the poll's first answer then tells a change made while the page was read
|
||||
states = vm_states(request.user, [compute])
|
||||
utils.refresh_instance_database(compute)
|
||||
instances = list(Instance.objects.filter(compute=compute).order_by("name").prefetch_related("userinstance_set"))
|
||||
instances = list(Instance.objects.filter(compute=compute).order_by("name").prefetch_related("userinstance_set", "tags"))
|
||||
read_list_rows(instances, [compute])
|
||||
|
||||
return render(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue