mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix: the user list, a user's VMs and the SSH keys come in name order
The user list counts API tokens, and a query with a count has no order of its own: PostgreSQL lists the users in any order. A user's page listed the VMs and the SSH keys as stored, so did the profile and the VM page's key choice.
This commit is contained in:
parent
94181cfc14
commit
72a2e448d4
5 changed files with 26 additions and 5 deletions
|
|
@ -22,6 +22,19 @@ class AccountPageTests(TestCase):
|
|||
def page(self):
|
||||
return self.client.get(reverse("accounts:account", args=[self.alice.pk]))
|
||||
|
||||
def test_the_vms_and_keys_are_in_name_order(self):
|
||||
compute = Compute.objects.create(name="ap-host", hostname="localhost", login="", password="", details="", type=4)
|
||||
for i, name in enumerate(("web", "db")):
|
||||
vm = Instance.objects.create(compute=compute, name=name, uuid=f"00000000-0000-0000-0000-00000000010{i}")
|
||||
UserInstance.objects.create(user=self.alice, instance=vm)
|
||||
UserSSHKey.objects.create(user=self.alice, keyname="desktop", keypublic=KEY)
|
||||
response = self.page()
|
||||
self.assertEqual([ui.instance.name for ui in response.context["user_insts"]], ["db", "web"])
|
||||
self.assertEqual([key.keyname for key in response.context["publickeys"]], ["desktop", "laptop"])
|
||||
self.client.force_login(self.alice)
|
||||
response = self.client.get(reverse("accounts:profile"))
|
||||
self.assertEqual([key.keyname for key in response.context["publickeys"]], ["desktop", "laptop"])
|
||||
|
||||
def test_the_permissions_are_marks_not_true_or_false(self):
|
||||
compute = Compute.objects.create(name="ap-host", hostname="localhost", login="", password="", details="", type=4)
|
||||
vm = Instance.objects.create(compute=compute, name="ap-vm", uuid="00000000-0000-0000-0000-000000000001")
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ from .utils import OTP_LINK, OTP_LINK_MAX_AGE, get_existing_totp_device, get_use
|
|||
|
||||
|
||||
def profile(request):
|
||||
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
|
||||
publickeys = UserSSHKey.objects.filter(user_id=request.user.id).order_by("keyname")
|
||||
profile_form = ProfileForm(request.POST or None, instance=request.user)
|
||||
ssh_key_form = UserSSHKeyForm()
|
||||
|
||||
|
|
@ -192,8 +192,9 @@ def ssh_key_delete(request, pk, user_id=None):
|
|||
@superuser_only
|
||||
def account(request, user_id):
|
||||
user = get_object_or_404(User, id=user_id)
|
||||
user_insts = UserInstance.objects.filter(user_id=user_id).select_related("instance__compute").prefetch_related("instance__tags")
|
||||
publickeys = UserSSHKey.objects.filter(user_id=user_id)
|
||||
user_insts = UserInstance.objects.filter(user_id=user_id).select_related("instance__compute").prefetch_related(
|
||||
"instance__tags").order_by("instance__name")
|
||||
publickeys = UserSSHKey.objects.filter(user_id=user_id).order_by("keyname")
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue