mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Adds user admin view
This commit is contained in:
parent
5416bb10fd
commit
43fc940a07
6 changed files with 103 additions and 2 deletions
|
@ -14,6 +14,10 @@
|
|||
{% if perms.bookwyrm.create_invites %}
|
||||
<h2 class="menu-label">{% trans "Manage Users" %}</h2>
|
||||
<ul class="menu-list">
|
||||
<li>
|
||||
{% url 'settings-users' as url %}
|
||||
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Users" %}</a>
|
||||
</li>
|
||||
<li>
|
||||
{% url 'settings-invite-requests' as url %}
|
||||
{% url 'settings-invites' as alt_url %}
|
||||
|
|
52
bookwyrm/templates/settings/user_admin.html
Normal file
52
bookwyrm/templates/settings/user_admin.html
Normal file
|
@ -0,0 +1,52 @@
|
|||
{% extends 'settings/admin_layout.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Users" %}{% endblock %}
|
||||
|
||||
{% block header %}{% trans "Users" %}{% endblock %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
<table class="table is-striped">
|
||||
<tr>
|
||||
{% url 'settings-users' as url %}
|
||||
<th>
|
||||
{% trans "Username" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="username" sort=sort text=text %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "Date Added" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "Last Active" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="last_active_date" sort=sort text=text %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "Status" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="is_active" sort=sort text=text %}
|
||||
</th>
|
||||
<th>
|
||||
{% trans "Remote server" as text %}
|
||||
{% include 'snippets/table-sort-header.html' with field="federated_server__server_name" sort=sort text=text %}
|
||||
</th>
|
||||
</tr>
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td>{{ user.username }}</td>
|
||||
<td>{{ user.created_date }}</td>
|
||||
<td>{{ user.last_active_date }}</td>
|
||||
<td>{% if user.is_active %}{% trans "Active" %}{% else %}{% trans "Inactive" %}{% endif %}</td>
|
||||
<td>
|
||||
{% if user.federated_server %}
|
||||
<a href="{% url 'settings-federated-server' user.federated_server.id %}">{{ user.federated_server.server_name }}</a>
|
||||
{% elif not user.local %}
|
||||
<em>{% trans "Not set" %}</em>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% include 'snippets/pagination.html' with page=users path=request.path %}
|
||||
{% endblock %}
|
||||
|
|
@ -2,11 +2,11 @@
|
|||
<a href="{{ url }}?sort={% if sort == field %}-{% endif %}{{ field }}">
|
||||
{{ text }}
|
||||
{% if sort == field %}
|
||||
<span class="icon icon-arrow-down">
|
||||
<span class="icon icon-arrow-up">
|
||||
<span class="is-sr-only">{% trans "Sorted asccending" %}</span>
|
||||
</span>
|
||||
{% elif sort == "-"|add:field %}
|
||||
<span class="icon icon-arrow-up">
|
||||
<span class="icon icon-arrow-down">
|
||||
<span class="is-sr-only">{% trans "Sorted descending" %}</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
|
|
|
@ -54,6 +54,7 @@ urlpatterns = [
|
|||
views.site.email_preview,
|
||||
name="settings-email-preview",
|
||||
),
|
||||
re_path(r"^settings/users", views.UserAdmin.as_view(), name="settings-users"),
|
||||
re_path(
|
||||
r"^settings/federation/?$",
|
||||
views.Federation.as_view(),
|
||||
|
|
|
@ -35,4 +35,5 @@ from .status import CreateStatus, DeleteStatus
|
|||
from .tag import Tag, AddTag, RemoveTag
|
||||
from .updates import get_notification_count, get_unread_status_count
|
||||
from .user import User, EditUser, Followers, Following
|
||||
from .user_admin import UserAdmin
|
||||
from .wellknown import webfinger, nodeinfo_pointer, nodeinfo, instance_info, peers
|
||||
|
|
43
bookwyrm/views/user_admin.py
Normal file
43
bookwyrm/views/user_admin.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
""" manage user """
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.settings import PAGE_LENGTH
|
||||
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(
|
||||
permission_required("bookwyrm.moderate_users", raise_exception=True),
|
||||
name="dispatch",
|
||||
)
|
||||
class UserAdmin(View):
|
||||
""" admin view of users on this server """
|
||||
|
||||
def get(self, request):
|
||||
""" list of users """
|
||||
try:
|
||||
page = int(request.GET.get("page", 1))
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
users = models.User.objects.all()
|
||||
|
||||
sort = request.GET.get("sort", "-created_date")
|
||||
sort_fields = [
|
||||
"created_date",
|
||||
"last_active_date",
|
||||
"username",
|
||||
"federated_server__server_name",
|
||||
"is_active",
|
||||
]
|
||||
if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
|
||||
users = users.order_by(sort)
|
||||
|
||||
paginated = Paginator(users, PAGE_LENGTH)
|
||||
data = {"users": paginated.page(page), "sort": sort}
|
||||
return TemplateResponse(request, "settings/user_admin.html", data)
|
Loading…
Reference in a new issue