1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +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:
catborise 2026-11-19 14:31:59 +03:00
parent 94181cfc14
commit 72a2e448d4
5 changed files with 26 additions and 5 deletions

View file

@ -32,6 +32,13 @@ class UserPagesTests(TestCase):
**changes}
return {key: value for key, value in data.items() if value != ""}
def test_the_list_is_in_name_order(self):
get_user_model().objects.create_user("up-bob")
get_user_model().objects.create_user("up-adam")
users = self.client.get(reverse("admin:user_list")).context["users"]
self.assertTrue(users.ordered) # SQLite keeps the name order without asking; PostgreSQL does not
self.assertEqual([user.username for user in users], sorted(user.username for user in users))
def test_an_administrator_cannot_block_delete_or_demote_themselves(self):
own = self.admin.pk
for response in (self.client.post(reverse("admin:user_block", args=[own])),

View file

@ -172,7 +172,7 @@ def user_list(request):
users = User.objects.annotate(
api_tokens=Count("auth_token_set", filter=live),
can_clone=Exists(clone.filter(Q(user=OuterRef("pk")) | Q(group__user=OuterRef("pk")))),
).prefetch_related("groups")
).order_by("username").prefetch_related("groups")
return render(
request,
"admin/user_list.html",