Adds raise_not_editable to User model

This model doens't inherit from BookwyrmModel for various reasons, but
it still needs to editability check.
This commit is contained in:
Mouse Reeve 2022-09-19 09:23:55 -07:00
parent aa67f23b03
commit 3f5eb6c682

View file

@ -5,6 +5,7 @@ from urllib.parse import urlparse
from django.apps import apps
from django.contrib.auth.models import AbstractUser, Group
from django.contrib.postgres.fields import ArrayField, CICharField
from django.core.exceptions import PermissionDenied
from django.dispatch import receiver
from django.db import models, transaction
from django.utils import timezone
@ -393,6 +394,12 @@ class User(OrderedCollectionPageMixin, AbstractUser):
editable=False,
).save(broadcast=False)
def raise_not_editable(self, viewer):
"""Who can edit the user object?"""
if self == viewer or viewer.has_perm("bookwyrm.moderate_user"):
return
raise PermissionDenied()
class KeyPair(ActivitypubMixin, BookWyrmModel):
"""public and private keys for a user"""