diff --git a/bookwyrm/migrations/0179_reportcomment_comment_type.py b/bookwyrm/migrations/0179_reportcomment_comment_type.py new file mode 100644 index 000000000..a8a446096 --- /dev/null +++ b/bookwyrm/migrations/0179_reportcomment_comment_type.py @@ -0,0 +1,36 @@ +# Generated by Django 3.2.18 on 2023-05-16 16:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0178_auto_20230328_2132"), + ] + + operations = [ + migrations.AddField( + model_name="reportcomment", + name="action_type", + field=models.CharField( + choices=[ + ("comment", "Comment"), + ("resolve", "Resolved report"), + ("reopen", "Re-opened report"), + ("message_reporter", "Messaged reporter"), + ("message_offender", "Messaged reported user"), + ("user_suspension", "Suspended user"), + ("user_unsuspension", "Un-suspended user"), + ("user_perms", "Changed user permission level"), + ("user_deletion", "Deleted user account"), + ("block_domain", "Blocked domain"), + ("approve_domain", "Approved domain"), + ("delete_item", "Deleted item"), + ], + default="comment", + max_length=20, + ), + ), + migrations.RenameModel("ReportComment", "ReportAction"), + ] diff --git a/bookwyrm/migrations/0180_alter_reportaction_options.py b/bookwyrm/migrations/0180_alter_reportaction_options.py new file mode 100644 index 000000000..2979d266e --- /dev/null +++ b/bookwyrm/migrations/0180_alter_reportaction_options.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.18 on 2023-06-21 22:01 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0179_reportcomment_comment_type"), + ] + + operations = [ + migrations.AlterModelOptions( + name="reportaction", + options={"ordering": ("created_date",)}, + ), + ] diff --git a/bookwyrm/migrations/0181_merge_20230806_2302.py b/bookwyrm/migrations/0181_merge_20230806_2302.py new file mode 100644 index 000000000..f4f05b886 --- /dev/null +++ b/bookwyrm/migrations/0181_merge_20230806_2302.py @@ -0,0 +1,13 @@ +# Generated by Django 3.2.20 on 2023-08-06 23:02 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0180_alter_reportaction_options"), + ("bookwyrm", "0180_alter_user_preferred_language"), + ] + + operations = [] diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index f5b72f3e4..7b779190b 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -20,7 +20,7 @@ from .readthrough import ReadThrough, ProgressUpdate, ProgressMode from .user import User, KeyPair from .annual_goal import AnnualGoal from .relationship import UserFollows, UserFollowRequest, UserBlocks -from .report import Report, ReportComment +from .report import Report, ReportAction from .federated_server import FederatedServer from .group import Group, GroupMember, GroupMemberInvitation diff --git a/bookwyrm/models/report.py b/bookwyrm/models/report.py index f6e665053..74a9bbe41 100644 --- a/bookwyrm/models/report.py +++ b/bookwyrm/models/report.py @@ -1,11 +1,27 @@ """ flagged for moderation """ from django.core.exceptions import PermissionDenied from django.db import models +from django.utils.translation import gettext_lazy as _ from bookwyrm.settings import DOMAIN from .base_model import BookWyrmModel +# Report action enums +COMMENT = "comment" +RESOLVE = "resolve" +REOPEN = "reopen" +MESSAGE_REPORTER = "message_reporter" +MESSAGE_OFFENDER = "message_offender" +USER_SUSPENSION = "user_suspension" +USER_UNSUSPENSION = "user_unsuspension" +USER_DELETION = "user_deletion" +USER_PERMS = "user_perms" +BLOCK_DOMAIN = "block_domain" +APPROVE_DOMAIN = "approve_domain" +DELETE_ITEM = "delete_item" + + class Report(BookWyrmModel): """reported status or user""" @@ -32,20 +48,65 @@ class Report(BookWyrmModel): def get_remote_id(self): return f"https://{DOMAIN}/settings/reports/{self.id}" + def comment(self, user, note): + """comment on a report""" + ReportAction.objects.create( + action_type=COMMENT, user=user, note=note, report=self + ) + + def resolve(self, user): + """Mark a report as complete""" + self.resolved = True + self.save() + ReportAction.objects.create(action_type=RESOLVE, user=user, report=self) + + def reopen(self, user): + """Wait! This report isn't complete after all""" + self.resolved = False + self.save() + ReportAction.objects.create(action_type=REOPEN, user=user, report=self) + + @classmethod + def record_action(cls, report_id: int, action: str, user): + """Note that someone did something""" + if not report_id: + return + report = cls.objects.get(id=report_id) + ReportAction.objects.create(action_type=action, user=user, report=report) + class Meta: """set order by default""" ordering = ("-created_date",) -class ReportComment(BookWyrmModel): +ReportActionTypes = [ + (COMMENT, _("Comment")), + (RESOLVE, _("Resolved report")), + (REOPEN, _("Re-opened report")), + (MESSAGE_REPORTER, _("Messaged reporter")), + (MESSAGE_OFFENDER, _("Messaged reported user")), + (USER_SUSPENSION, _("Suspended user")), + (USER_UNSUSPENSION, _("Un-suspended user")), + (USER_PERMS, _("Changed user permission level")), + (USER_DELETION, _("Deleted user account")), + (BLOCK_DOMAIN, _("Blocked domain")), + (APPROVE_DOMAIN, _("Approved domain")), + (DELETE_ITEM, _("Deleted item")), +] + + +class ReportAction(BookWyrmModel): """updates on a report""" user = models.ForeignKey("User", on_delete=models.PROTECT) + action_type = models.CharField( + max_length=20, blank=False, default="comment", choices=ReportActionTypes + ) note = models.TextField() report = models.ForeignKey(Report, on_delete=models.PROTECT) class Meta: """sort comments""" - ordering = ("-created_date",) + ordering = ("created_date",) diff --git a/bookwyrm/templates/settings/reports/report.html b/bookwyrm/templates/settings/reports/report.html index ca105701f..df45341c6 100644 --- a/bookwyrm/templates/settings/reports/report.html +++ b/bookwyrm/templates/settings/reports/report.html @@ -1,6 +1,7 @@ {% extends 'settings/layout.html' %} {% load i18n %} {% load humanize %} +{% load utilities %} {% load feed_page_tags %} {% block title %} @@ -21,7 +22,7 @@
{{ comment.note }}
-