Add admin capcodes
Sometimes, it is necessary for an admin or other moderator to reveal themselves. Capcodes allow them to do so by appending a special colored portion at the end of their name on a post. This adds object-level permissions, so if you have a moderator who shouldn't be able to use the "admin" capcode, you can give them permission only to the "moderator" capcode. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
@@ -39,12 +40,21 @@ class ReplyForm(PostForm):
|
||||
|
||||
class Meta:
|
||||
model = Post
|
||||
fields = ["name", "text", "bump", "image"]
|
||||
fields = ["name", "text", "bump", "capcode", "image"]
|
||||
|
||||
def __init__(self, *args, op, reply, **kwargs):
|
||||
def __init__(self, *args, user, op, **kwargs):
|
||||
super(ReplyForm, self).__init__(*args, **kwargs)
|
||||
self.instance.op = op
|
||||
self.instance.reply = reply
|
||||
self.user = user
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
# TODO
|
||||
# Check if the user has the right permissions to use the selected capcode
|
||||
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")
|
||||
|
||||
|
||||
class ReportForm(ModelForm):
|
||||
|
||||
Reference in New Issue
Block a user