Adds models for reporting

This commit is contained in:
Mouse Reeve 2021-03-08 17:16:59 -08:00
parent 7337a357fa
commit e59c127686
7 changed files with 90 additions and 8 deletions

3
.gitignore vendored
View file

@ -2,6 +2,7 @@
/venv /venv
*.pyc *.pyc
*.swp *.swp
**/__pycache__
# VSCode # VSCode
/.vscode /.vscode
@ -15,4 +16,4 @@
/images/ /images/
# Testing # Testing
.coverage .coverage

View file

@ -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,
},
),
]

View file

@ -21,6 +21,7 @@ from .tag import Tag, UserTag
from .user import User, KeyPair, AnnualGoal from .user import User, KeyPair, AnnualGoal
from .relationship import UserFollows, UserFollowRequest, UserBlocks from .relationship import UserFollows, UserFollowRequest, UserBlocks
from .report import Report, ReportComment
from .federated_server import FederatedServer from .federated_server import FederatedServer
from .import_job import ImportJob, ImportItem from .import_job import ImportJob, ImportItem

View file

@ -4,7 +4,7 @@ from .base_model import BookWyrmModel
class FederatedServer(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) server_name = models.CharField(max_length=255, unique=True)
# federated, blocked, whatever else # federated, blocked, whatever else

23
bookwyrm/models/report.py Normal file
View file

@ -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)

View file

@ -20,6 +20,13 @@ class ReportViews(TestCase):
local=True, local=True,
localname="mouse", 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() models.SiteSettings.objects.create()
def test_reports_page(self): def test_reports_page(self):
@ -39,7 +46,7 @@ class ReportViews(TestCase):
request = self.factory.get("") request = self.factory.get("")
request.user = self.local_user request.user = self.local_user
request.user.is_superuser = True 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) result = view(request, report.id)

View file

@ -8,7 +8,7 @@ from django.views import View
from bookwyrm import models from bookwyrm import models
# pylint: disable= no-self-use # pylint: disable=no-self-use
@method_decorator(login_required, name="dispatch") @method_decorator(login_required, name="dispatch")
@method_decorator( @method_decorator(
permission_required("bookwyrm.moderate_user", raise_exception=True), permission_required("bookwyrm.moderate_user", raise_exception=True),
@ -21,11 +21,13 @@ from bookwyrm import models
class Reports(View): class Reports(View):
""" list of reports """ """ list of reports """
def get(self, request, status="open"): def get(self, request):
""" view current reports """ """ view current reports """
resolved = request.GET.get("resolved")
data = { data = {
"status": status "resolved": resolved,
} # {"reports": models.Report.objects.filter(status=status)} "reports": models.Report.objects.filter(resolved=resolved),
}
return TemplateResponse(request, "settings/reports.html", data) return TemplateResponse(request, "settings/reports.html", data)
@ -34,5 +36,5 @@ class Report(View):
def get(self, request, report_id): def get(self, request, report_id):
""" load a report """ """ 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) return TemplateResponse(request, "settings/report.html", data)