forked from mirrors/bookwyrm
Option to deactivate reported users
This commit is contained in:
parent
422cd2da73
commit
677a49fee3
6 changed files with 52 additions and 6 deletions
|
@ -15,9 +15,18 @@
|
|||
|
||||
<div class="block content">
|
||||
<h3>{% trans "Actions" %}</h3>
|
||||
<div class="field is-grouped">
|
||||
<a class="button" href="{% url 'direct-messages-user' report.user.username %}">{% trans "Send direct message" %}</a>
|
||||
<button class="button">Suspend</button>
|
||||
<div class="is-flex">
|
||||
<p class="mr-1">
|
||||
<a class="button" href="{% url 'direct-messages-user' report.user.username %}">{% trans "Send direct message" %}</a>
|
||||
</p>
|
||||
<form name="deactivate" method="post" action="{% url 'settings-report-deactivate' report.id %}">
|
||||
{% csrf_token %}
|
||||
{% if report.user.is_active %}
|
||||
<button type="submit" class="button is-danger is-light">{% trans "Deactivate user" %}</button>
|
||||
{% else %}
|
||||
<button class="button">{% trans "Reactivate user" %}</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% for comment in report.reportcomment_set.all %}
|
||||
|
|
|
@ -8,8 +8,11 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block card-content %}
|
||||
<div class="block">
|
||||
{% if report.note %}{{ report.note }}{% else %}<em>{% trans "No notes provided" %}</em>{% endif %}
|
||||
<div class="block content">
|
||||
<p>
|
||||
{% if report.note %}{{ report.note }}{% else %}<em>{% trans "No notes provided" %}</em>{% endif %}
|
||||
</p>
|
||||
<p><a href="{{ report.user.local_path }}">{% trans "View user profile" %}</a></p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -98,3 +98,22 @@ class ReportViews(TestCase):
|
|||
views.resolve_report(request, report.id)
|
||||
report.refresh_from_db()
|
||||
self.assertFalse(report.resolved)
|
||||
|
||||
|
||||
def test_deactivate_user(self):
|
||||
""" toggle whether a user is able to log in """
|
||||
self.assertTrue(self.rat.is_active)
|
||||
report = models.Report.objects.create(reporter=self.local_user, user=self.rat)
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
request.user.is_superuser = True
|
||||
|
||||
# resolve
|
||||
views.deactivate_user(request, report.id)
|
||||
self.rat.refresh_from_db()
|
||||
self.assertFalse(self.rat.is_active)
|
||||
|
||||
# un-resolve
|
||||
views.deactivate_user(request, report.id)
|
||||
self.rat.refresh_from_db()
|
||||
self.assertTrue(self.rat.is_active)
|
||||
|
|
|
@ -62,6 +62,11 @@ urlpatterns = [
|
|||
views.Report.as_view(),
|
||||
name="settings-report",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/reports/(?P<report_id>\d+)/deactivate/?$",
|
||||
views.deactivate_user,
|
||||
name="settings-report-deactivate",
|
||||
),
|
||||
re_path(
|
||||
r"^settings/reports/(?P<report_id>\d+)/resolve/?$",
|
||||
views.resolve_report,
|
||||
|
|
|
@ -20,7 +20,7 @@ from .notifications import Notifications
|
|||
from .outbox import Outbox
|
||||
from .reading import edit_readthrough, create_readthrough, delete_readthrough
|
||||
from .reading import start_reading, finish_reading, delete_progressupdate
|
||||
from .reports import Report, Reports, make_report, resolve_report
|
||||
from .reports import Report, Reports, make_report, resolve_report, deactivate_user
|
||||
from .rss_feed import RssFeed
|
||||
from .password import PasswordResetRequest, PasswordReset, ChangePassword
|
||||
from .search import Search
|
||||
|
|
|
@ -50,6 +50,16 @@ class Report(View):
|
|||
return TemplateResponse(request, "moderation/report.html", data)
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required("bookwyrm_moderate_user")
|
||||
def deactivate_user(_, report_id):
|
||||
""" mark an account as inactive """
|
||||
report = get_object_or_404(models.Report, id=report_id)
|
||||
report.user.is_active = not report.user.is_active
|
||||
report.user.save()
|
||||
return redirect("settings-report", report.id)
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required("bookwyrm_moderate_post")
|
||||
def resolve_report(_, report_id):
|
||||
|
|
Loading…
Reference in a new issue