diff --git a/bookwyrm/templates/moderation/report.html b/bookwyrm/templates/moderation/report.html index 32fdf6d74..b2e61cc44 100644 --- a/bookwyrm/templates/moderation/report.html +++ b/bookwyrm/templates/moderation/report.html @@ -15,9 +15,18 @@

{% trans "Actions" %}

-
- {% trans "Send direct message" %} - +
+

+ {% trans "Send direct message" %} +

+
+ {% csrf_token %} + {% if report.user.is_active %} + + {% else %} + + {% endif %} +
{% for comment in report.reportcomment_set.all %} diff --git a/bookwyrm/templates/moderation/report_preview.html b/bookwyrm/templates/moderation/report_preview.html index 3888be27c..c35010cf6 100644 --- a/bookwyrm/templates/moderation/report_preview.html +++ b/bookwyrm/templates/moderation/report_preview.html @@ -8,8 +8,11 @@ {% endblock %} {% block card-content %} -
- {% if report.note %}{{ report.note }}{% else %}{% trans "No notes provided" %}{% endif %} +
+

+ {% if report.note %}{{ report.note }}{% else %}{% trans "No notes provided" %}{% endif %} +

+

{% trans "View user profile" %}

{% endblock %} diff --git a/bookwyrm/tests/views/test_reports.py b/bookwyrm/tests/views/test_reports.py index 1a5bfd158..724e7b5a6 100644 --- a/bookwyrm/tests/views/test_reports.py +++ b/bookwyrm/tests/views/test_reports.py @@ -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) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 0ad464f41..26ce67a3c 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -62,6 +62,11 @@ urlpatterns = [ views.Report.as_view(), name="settings-report", ), + re_path( + r"^settings/reports/(?P\d+)/deactivate/?$", + views.deactivate_user, + name="settings-report-deactivate", + ), re_path( r"^settings/reports/(?P\d+)/resolve/?$", views.resolve_report, diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 63ab98e54..606624b84 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -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 diff --git a/bookwyrm/views/reports.py b/bookwyrm/views/reports.py index ad22da2ba..2ba0d27ac 100644 --- a/bookwyrm/views/reports.py +++ b/bookwyrm/views/reports.py @@ -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):