diff --git a/.gitignore b/.gitignore index 1384056f..4b5b7fef 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /venv *.pyc *.swp +**/__pycache__ # VSCode /.vscode @@ -15,4 +16,4 @@ /images/ # Testing -.coverage \ No newline at end of file +.coverage diff --git a/bookwyrm/migrations/0049_report_reportcomment.py b/bookwyrm/migrations/0049_report_reportcomment.py new file mode 100644 index 00000000..deb8ba6f --- /dev/null +++ b/bookwyrm/migrations/0049_report_reportcomment.py @@ -0,0 +1,48 @@ +# Generated by Django 3.0.7 on 2021-03-09 00:55 + +import bookwyrm.models.fields +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0048_merge_20210308_1754'), + ] + + operations = [ + migrations.CreateModel( + name='Report', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_date', models.DateTimeField(auto_now_add=True)), + ('updated_date', models.DateTimeField(auto_now=True)), + ('remote_id', bookwyrm.models.fields.RemoteIdField(max_length=255, null=True, validators=[bookwyrm.models.fields.validate_remote_id])), + ('note', models.TextField(blank=True, null=True)), + ('resolved', models.BooleanField(default=False)), + ('reporter', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='reporter', to=settings.AUTH_USER_MODEL)), + ('statuses', models.ManyToManyField(to='bookwyrm.Status')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='ReportComment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_date', models.DateTimeField(auto_now_add=True)), + ('updated_date', models.DateTimeField(auto_now=True)), + ('remote_id', bookwyrm.models.fields.RemoteIdField(max_length=255, null=True, validators=[bookwyrm.models.fields.validate_remote_id])), + ('note', models.TextField()), + ('report', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='bookwyrm.Report')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index 67ee16d3..326a673e 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -21,6 +21,7 @@ from .tag import Tag, UserTag from .user import User, KeyPair, AnnualGoal from .relationship import UserFollows, UserFollowRequest, UserBlocks +from .report import Report, ReportComment from .federated_server import FederatedServer from .import_job import ImportJob, ImportItem diff --git a/bookwyrm/models/federated_server.py b/bookwyrm/models/federated_server.py index ce804310..8f7d903e 100644 --- a/bookwyrm/models/federated_server.py +++ b/bookwyrm/models/federated_server.py @@ -4,7 +4,7 @@ from .base_model import BookWyrmModel class FederatedServer(BookWyrmModel): - """ store which server's we federate with """ + """ store which servers we federate with """ server_name = models.CharField(max_length=255, unique=True) # federated, blocked, whatever else diff --git a/bookwyrm/models/report.py b/bookwyrm/models/report.py new file mode 100644 index 00000000..afbc356b --- /dev/null +++ b/bookwyrm/models/report.py @@ -0,0 +1,23 @@ +""" flagged for moderation """ +from django.db import models +from .base_model import BookWyrmModel + + +class Report(BookWyrmModel): + """ reported status or user """ + + reporter = models.ForeignKey( + "User", related_name="reporter", on_delete=models.PROTECT + ) + note = models.TextField(null=True, blank=True) + user = models.ForeignKey("User", on_delete=models.PROTECT) + statuses = models.ManyToManyField("Status") + resolved = models.BooleanField(default=False) + + +class ReportComment(BookWyrmModel): + """ updates on a report """ + + user = models.ForeignKey("User", on_delete=models.PROTECT) + note = models.TextField() + report = models.ForeignKey(Report, on_delete=models.PROTECT) diff --git a/bookwyrm/tests/views/test_reports.py b/bookwyrm/tests/views/test_reports.py index 3b8dec26..d35633cb 100644 --- a/bookwyrm/tests/views/test_reports.py +++ b/bookwyrm/tests/views/test_reports.py @@ -20,6 +20,13 @@ class ReportViews(TestCase): local=True, localname="mouse", ) + self.local_user = models.User.objects.create_user( + "rat@local.com", + "rat@mouse.mouse", + "password", + local=True, + localname="rat", + ) models.SiteSettings.objects.create() def test_reports_page(self): @@ -39,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() + report = models.Report.objects.create(reporter=self.local_user, user=self.rat) result = view(request, report.id) diff --git a/bookwyrm/views/reports.py b/bookwyrm/views/reports.py index a90fffaf..2e374d5e 100644 --- a/bookwyrm/views/reports.py +++ b/bookwyrm/views/reports.py @@ -8,7 +8,7 @@ from django.views import View from bookwyrm import models -# pylint: disable= no-self-use +# pylint: disable=no-self-use @method_decorator(login_required, name="dispatch") @method_decorator( permission_required("bookwyrm.moderate_user", raise_exception=True), @@ -21,11 +21,13 @@ from bookwyrm import models class Reports(View): """ list of reports """ - def get(self, request, status="open"): + def get(self, request): """ view current reports """ + resolved = request.GET.get("resolved") data = { - "status": status - } # {"reports": models.Report.objects.filter(status=status)} + "resolved": resolved, + "reports": models.Report.objects.filter(resolved=resolved), + } return TemplateResponse(request, "settings/reports.html", data) @@ -34,5 +36,5 @@ class Report(View): def get(self, request, report_id): """ load a report """ - data = {"report": get_object_or_404(models.REport, id=report_id)} + data = {"report": get_object_or_404(models.Report, id=report_id)} return TemplateResponse(request, "settings/report.html", data)