mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
commit
e3abc96266
9 changed files with 165 additions and 5 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 %}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<dt>{% trans "Users:" %}</dt>
|
||||
<dd>
|
||||
{{ users.count }}
|
||||
{# {% if server.user_set.count %}(<a href="{% url 'settings-users' server=server.id %}">{% trans "View all users" %}</a>){% endif %} #}
|
||||
{% if server.user_set.count %}(<a href="{% url 'settings-users' %}?server={{ server.id }}">{% trans "View all" %}</a>){% endif %}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="is-flex">
|
||||
|
|
59
bookwyrm/templates/settings/user_admin.html
Normal file
59
bookwyrm/templates/settings/user_admin.html
Normal file
|
@ -0,0 +1,59 @@
|
|||
{% extends 'settings/admin_layout.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Users" %}{% endblock %}
|
||||
|
||||
{% block header %}
|
||||
{% if server %}
|
||||
{% blocktrans with server_name=server.server_name %}Users: <small>{{ server_name }}</small>{% endblocktrans %}
|
||||
<a href="{% url 'settings-users' %}" class="help has-text-weight-normal">Clear filters</a>
|
||||
{% else %}
|
||||
{% trans "Users" %}
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
|
|
|
@ -3,8 +3,7 @@ from django.template.response import TemplateResponse
|
|||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm import views
|
||||
from bookwyrm import models, views
|
||||
|
||||
|
||||
class FederationViews(TestCase):
|
||||
|
@ -32,3 +31,16 @@ class FederationViews(TestCase):
|
|||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_server_page(self):
|
||||
""" there are so many views, this just makes sure it LOADS """
|
||||
server = models.FederatedServer.objects.create(server_name="hi.there.com")
|
||||
view = views.FederatedServer.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
||||
result = view(request, server.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
|
33
bookwyrm/tests/views/test_user_admin.py
Normal file
33
bookwyrm/tests/views/test_user_admin.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
""" test for app action functionality """
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models, views
|
||||
|
||||
|
||||
class UserAdminViews(TestCase):
|
||||
""" every response to a get request, html or json """
|
||||
|
||||
def setUp(self):
|
||||
""" we need basic test data and mocks """
|
||||
self.factory = RequestFactory()
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_user_admin_page(self):
|
||||
""" there are so many views, this just makes sure it LOADS """
|
||||
view = views.UserAdmin.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
|
@ -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
|
||||
|
|
50
bookwyrm/views/user_admin.py
Normal file
50
bookwyrm/views/user_admin.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
""" manage user """
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.shortcuts import get_object_or_404
|
||||
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
|
||||
|
||||
filters = {}
|
||||
server = request.GET.get("server")
|
||||
if server:
|
||||
server = get_object_or_404(models.FederatedServer, id=server)
|
||||
filters["federated_server"] = server
|
||||
|
||||
users = models.User.objects.filter(**filters).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, "server": server}
|
||||
return TemplateResponse(request, "settings/user_admin.html", data)
|
Loading…
Reference in a new issue