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:
2022-06-28 21:37:45 -07:00
parent 29dff20db9
commit ab749359fa
9 changed files with 110 additions and 46 deletions

View File

@@ -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):