mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 05:21:08 +00:00
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:
parent
aa67f23b03
commit
3f5eb6c682
1 changed files with 7 additions and 0 deletions
|
@ -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"""
|
||||
|
|
Loading…
Reference in a new issue