Override raise_not_editable for report model

This model uses "reporter" as the field that represents the onwer of the
object, and "user" and the subject. In retrospect, maybe not the ideal
way to do it.
This commit is contained in:
Mouse Reeve 2022-09-19 09:20:07 -07:00
parent 543d13af6e
commit aa67f23b03
2 changed files with 9 additions and 0 deletions

View file

@ -1,5 +1,7 @@
""" flagged for moderation """
from django.core.exceptions import PermissionDenied
from django.db import models
from bookwyrm.settings import DOMAIN
from .base_model import BookWyrmModel
@ -21,6 +23,12 @@ class Report(BookWyrmModel):
links = models.ManyToManyField("Link", blank=True)
resolved = models.BooleanField(default=False)
def raise_not_editable(self, viewer):
"""instead of user being the owner field, it's reporter"""
if self.reporter == viewer:
return
raise PermissionDenied()
def get_remote_id(self):
return f"https://{DOMAIN}/settings/reports/{self.id}"

View file

@ -11,6 +11,7 @@ from bookwyrm.tests.validate_html import validate_html
class ReportViews(TestCase):
"""every response to a get request, html or json"""
# pylint: disable=invalid-name
def setUp(self):
"""we need basic test data and mocks"""
self.factory = RequestFactory()