1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

perf(admin): the Users page tells who can clone in one query

Each row of the Users page asked has_perm whether its user may clone:
two queries a user (the user's permissions and the groups'). The list's
query now annotates it with one Exists over the clone permission, given
to the user or to a group of the user; a blocked user is shown without
it, as has_perm did. The page's query count no longer grows with the
users.
This commit is contained in:
catborise 2026-11-04 21:22:46 +03:00
parent 40087143a1
commit 2484d4efb3
3 changed files with 38 additions and 8 deletions

View file

@ -1,7 +1,6 @@
{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load common_tags %}
{% load bootstrap_icons %}
{% block title %}{{ title }}{% endblock %}
@ -22,7 +21,6 @@
</div>
<div class="list-group list-group-flush searchable">
{% for user in users %}
{% has_perm user 'instances.clone_instances' as can_clone %}
<div class="list-group-item py-3" data-search="{{ user.username }} {{ user.email }}{% for group in user.groups.all %} {{ group.name }}{% endfor %} {% if user.is_superuser %}{% trans "Superuser" %}{% elif user.is_staff %}{% trans "Template editor" %}{% else %}{% trans "User" %}{% endif %} {% if user.is_active %}{% trans "Active" %}{% else %}{% trans "Blocked" %}{% endif %}">
<div class="row g-2 align-items-center">
<div class="col-12 col-md-4">
@ -46,11 +44,11 @@
<div class="d-flex flex-wrap align-items-center gap-2">
{% for group in user.groups.all %}<span class="badge text-bg-light border mw-100 text-wrap text-break">{{ group.name }}</span>{% endfor %}
{# a superuser has every permission: only a granted clone permission is news #}
{% if can_clone and not user.is_superuser %}<span>{% trans "Can clone" %}</span>{% endif %}
{% if user.is_active and user.can_clone and not user.is_superuser %}<span>{% trans "Can clone" %}</span>{% endif %}
{% if user.api_tokens %}
<a href="{% url 'accounts:account' user.id %}#apitokens">{% blocktrans count count=user.api_tokens %}{{ count }} API token{% plural %}{{ count }} API tokens{% endblocktrans %}</a>
{% endif %}
{% if not user.groups.all and not user.api_tokens %}{% if user.is_superuser or not can_clone %}
{% if not user.groups.all and not user.api_tokens %}{% if user.is_superuser or not user.is_active or not user.can_clone %}
<span class="text-body-secondary">{% trans "No groups or API tokens" %}</span>
{% endif %}{% endif %}
</div>