mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-11 09:45:27 +00:00
Check perms on site model form
This commit is contained in:
parent
b0d8697006
commit
3fd573c0da
2 changed files with 9 additions and 1 deletions
|
@ -3,6 +3,7 @@ import datetime
|
|||
from urllib.parse import urljoin
|
||||
import uuid
|
||||
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import models, IntegrityError
|
||||
from django.dispatch import receiver
|
||||
from django.utils import timezone
|
||||
|
@ -114,6 +115,13 @@ class SiteSettings(models.Model):
|
|||
self.invite_question_text = "What is your favourite book?"
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def raise_not_editable(self, viewer):
|
||||
"""Check if the user has the right permissions"""
|
||||
if viewer.has_perm("bookwyrm.edit_instance_settings"):
|
||||
return
|
||||
raise PermissionDenied()
|
||||
|
||||
|
||||
class Theme(models.Model):
|
||||
"""Theme files"""
|
||||
|
|
|
@ -29,7 +29,7 @@ class Site(View):
|
|||
if not form.is_valid():
|
||||
data = {"site_form": form}
|
||||
return TemplateResponse(request, "settings/site.html", data)
|
||||
site = form.save()
|
||||
site = form.save(request)
|
||||
|
||||
data = {"site_form": forms.SiteForm(instance=site), "success": True}
|
||||
return TemplateResponse(request, "settings/site.html", data)
|
||||
|
|
Loading…
Reference in a new issue