Resolve and re-open reports

This commit is contained in:
Mouse Reeve 2021-03-12 10:22:03 -08:00
parent 4583662f51
commit bedc9e0a88
5 changed files with 50 additions and 3 deletions

View file

@ -21,6 +21,15 @@
{{ report.created_date | naturaltime }}
</div>
<div class="card-footer-item">
<button class="button">{% trans "Mark as resolved" %}</button>
<form name="resolve" method="post" action="{% url 'settings-report-resolve' report.id %}">
{% csrf_token %}
<button class="button" type="submit">
{% if report.resolved %}
{% trans "Re-open" %}
{% else %}
{% trans "Resolve" %}
{% endif %}
</button>
</form>
</div>
{% endblock %}

View file

@ -46,7 +46,7 @@ class ReportViews(TestCase):
request = self.factory.get("")
request.user = self.local_user
request.user.is_superuser = True
report = models.Report.objects.create(reporter=self.local_user, user=self.rat)
models.Report.objects.create(reporter=self.local_user, user=self.rat)
result = view(request)
self.assertIsInstance(result, TemplateResponse)
@ -80,3 +80,21 @@ class ReportViews(TestCase):
report = models.Report.objects.get()
self.assertEqual(report.reporter, self.local_user)
self.assertEqual(report.user, self.rat)
def test_resolve_report(self):
""" toggle report resolution status """
report = models.Report.objects.create(reporter=self.local_user, user=self.rat)
self.assertFalse(report.resolved)
request = self.factory.post("")
request.user = self.local_user
request.user.is_superuser = True
# resolve
views.resolve_report(request, report.id)
report.refresh_from_db()
self.assertTrue(report.resolved)
# un-resolve
views.resolve_report(request, report.id)
report.refresh_from_db()
self.assertFalse(report.resolved)

View file

@ -62,6 +62,11 @@ urlpatterns = [
views.Report.as_view(),
name="settings-report",
),
re_path(
r"^settings/reports/(?P<report_id>\d+)/resolve/?$",
views.resolve_report,
name="settings-report-resolve",
),
re_path(r"^report/?$", views.make_report, name="report"),
# landing pages
re_path(r"^about/?$", views.About.as_view()),

View file

@ -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
from .reports import Report, Reports, make_report, resolve_report
from .rss_feed import RssFeed
from .password import PasswordResetRequest, PasswordReset, ChangePassword
from .search import Search

View file

@ -49,6 +49,21 @@ class Report(View):
data = {"report": get_object_or_404(models.Report, id=report_id)}
return TemplateResponse(request, "moderation/report.html", data)
def post(self, request, report_id):
""" update a report """
@login_required
@permission_required("bookwyrm_moderate_post")
def resolve_report(_, report_id):
""" mark a report as (un)resolved """
report = get_object_or_404(models.Report, id=report_id)
report.resolved = not report.resolved
report.save()
if not report.resolved:
return redirect("settings-report", report.id)
return redirect("settings-reports")
@login_required
@require_POST