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:
@@ -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
|
||||
|
||||
@@ -93,8 +93,10 @@ class Post(models.Model):
|
||||
ip = models.GenericIPAddressField()
|
||||
# Capcode
|
||||
capcode = models.ForeignKey("Capcode", null=True, blank=True, on_delete=SET_NULL)
|
||||
# Post is stickied
|
||||
# Post is stickied - it remains at the top of the bump list.
|
||||
sticky = models.BooleanField(default=False, blank=True)
|
||||
# Post is locked - nobody can post in it.
|
||||
lock = models.BooleanField(default=False, blank=True)
|
||||
# Creation time
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
# Last bump time
|
||||
@@ -122,6 +124,7 @@ class Post(models.Model):
|
||||
permissions = [
|
||||
("set_sticky", "Can sticky post"),
|
||||
("set_bump", "Can bumplock post"),
|
||||
("set_lock", "Can lock post"),
|
||||
]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
@@ -27,9 +27,12 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Post ID, sticky, username, time #}
|
||||
{# Post ID, status icons, username, time #}
|
||||
{% if post.sticky and not post.op %}
|
||||
<span title="Stickied" class="fa fa-sticky-note"></span>
|
||||
<span title="Stickied" class="fa fa-thumb-tack"></span>
|
||||
{% endif %}
|
||||
{% if post.lock and not post.op %}
|
||||
<span title="Locked" class="fa fa-lock"></span>
|
||||
{% endif %}
|
||||
<a href="#p{{post.id}}">#.</a>
|
||||
<span class="post_id">{{post.id}}</span>
|
||||
|
||||
@@ -28,17 +28,32 @@ input[type=text] {
|
||||
{% block content %}
|
||||
<form method="post" action="{% url 'board:reply_create' url=board.url id=post.id %}" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
{{form.non_field_errors}}
|
||||
{% endif %}
|
||||
<table>
|
||||
{% for field in form %}
|
||||
{% if field.name != "capcode" %}
|
||||
<tr>
|
||||
<th>{{field.label_tag}}</th>
|
||||
<td>{{field}}</td>
|
||||
</tr>
|
||||
{% if field.errors %}
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>{{field.errors}}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th>{{field.label_tag}}</th>
|
||||
<td>{{field}}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if capcodes %}
|
||||
<tr>
|
||||
{% if form.capcode.errors %}
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>{{form.capcode.errors}}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<th>{{form.capcode.label_tag}}</th>
|
||||
<td>
|
||||
{{form.capcode}}
|
||||
|
||||
Reference in New Issue
Block a user