Skip to content
Snippets Groups Projects
Commit b3608be9 authored by Fredrik Jonsson's avatar Fredrik Jonsson
Browse files

Add roles to the user admin index page.

parent c9fb73f3
No related branches found
No related tags found
No related merge requests found
...@@ -95,6 +95,10 @@ class User(AbstractUser): ...@@ -95,6 +95,10 @@ class User(AbstractUser):
def get_short_name(self): def get_short_name(self):
return self.email return self.email
@cached_property
def roles(self):
return list(self.groups.values_list('name', flat=True))
@cached_property @cached_property
def is_apply_staff(self): def is_apply_staff(self):
return self.groups.filter(name=STAFF_GROUP_NAME).exists() or self.is_superuser return self.groups.filter(name=STAFF_GROUP_NAME).exists() or self.is_superuser
......
{% load i18n wagtailusers_tags wagtailadmin_tags %}
<table class="listing">
<thead>
<tr>
<th class="name">
{% trans "Name" %}
{% if ordering == "name" %}
<a href="{% url 'wagtailusers_users:index' %}" class="icon icon-arrow-down-after teal"></a>
{% else %}
<a href="{% url 'wagtailusers_users:index' %}?ordering=name" class="icon icon-arrow-down-after"></a>
{% endif %}
</th>
<th class="username">
{% trans "Username" %}
{% if ordering == "username" %}
<a href="{% url 'wagtailusers_users:index' %}" class="icon icon-arrow-down-after teal"></a>
{% else %}
<a href="{% url 'wagtailusers_users:index' %}?ordering=username" class="icon icon-arrow-down-after"></a>
{% endif %}
</th>
<th class="level">{% trans "Role" %}</th>
<th class="status">{% trans "Status" %}</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td class="title" valign="top">
<h2>
<span class="avatar small"><img src="{% avatar_url user size=25 %}" /></span>
<a href="{% url 'wagtailusers_users:edit' user.pk %}">{{ user.get_full_name|default:user.get_username }}</a>
</h2>
<ul class="actions">
{% user_listing_buttons user %}
</ul>
</td>
<td class="username" valign="top">{{ user.get_username }}</td>
<td class="level" valign="top">{{ user.roles|join:', ' }}{% if user.is_superuser %} ({% trans "Admin" %}){% endif %}</td>
<td class="status" valign="top"><div class="status-tag {% if user.is_active %}primary{% endif %}">{% if user.is_active %}{% trans "Active" %}{% else %}{% trans "Inactive" %}{% endif %}</div></td>
</tr>
{% endfor %}
</tbody>
</table>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment