Add thread locking and permissions

Mods can lock threads from replying now. Yay!

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-07-08 21:55:25 -07:00
parent e866cbae0f
commit a3ebf75e83
4 changed files with 36 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ from django import forms
from django.forms import ModelForm, ModelChoiceField
from django.forms.models import fields_for_model
from django.utils import timezone
from django.utils.translation import gettext as _
from guardian.shortcuts import get_objects_for_user
from board.models import Ban, Post, Report, ReportReason, ReportRecord
from hcaptcha.fields import hCaptchaField
@@ -38,7 +39,7 @@ class PostForm(ModelForm):
capcode = self.cleaned_data["capcode"]
if capcode:
if not self.user or not self.user.has_perm("board.use_capcode", capcode):
raise ValidationError("Could not create post")
raise ValidationError(_("Could not create post"))
class ReplyForm(PostForm):
@@ -67,10 +68,12 @@ class ReplyForm(PostForm):
def clean(self):
super().clean()
if self.instance.op.lock:
raise ValidationError(_("This thread is locked, you cannot reply to it"))
capcode = self.cleaned_data["capcode"]
if capcode:
if not self.user or not self.user.has_perm("board.use_capcode", capcode):
raise ValidationError("Could not create post")
raise ValidationError(_("Could not create post"))
class ReportForm(ModelForm):
@@ -142,7 +145,7 @@ class PostModifyForm(ModelForm):
model = Post
# we specify fields up here too because otherwise they won't be
# recognized by the form to update values
fields = ["sticky", "bump"]
fields = ["sticky", "bump", "lock"]
def __init__(self, *args, user, **kwargs):
super(PostModifyForm, self).__init__(*args, **kwargs)
@@ -152,6 +155,8 @@ class PostModifyForm(ModelForm):
fields += ["sticky"]
if self.user.has_perm("board.set_bump"):
fields += ["bump"]
if self.user.has_perm("board.set_lock") and not self.instance.op:
fields += ["lock"]
# NOTE:
# We do *not* need to check permissions against these fields we're
# setting down here in the self.clean() function in the case that a