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,5 +1,6 @@
|
||||
from typing import Any, Dict
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model, get_user
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db.models import Q
|
||||
@@ -9,6 +10,9 @@ from django.views.generic.base import TemplateView
|
||||
from django.views.generic import edit
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
|
||||
from guardian.shortcuts import get_objects_for_user
|
||||
|
||||
from board.forms import BanForm, PostForm, ReplyForm, ReportForm
|
||||
from board.models import Ban, BanTemplate, Board, Post, Report
|
||||
from board.utils import *
|
||||
@@ -26,6 +30,9 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class BannedView(TemplateView):
|
||||
template_name = "board/banned.html"
|
||||
|
||||
@@ -121,7 +128,9 @@ class ReplyCreateView(CreateView):
|
||||
post_id = self.kwargs["id"]
|
||||
context["post"] = get_object_or_404(Post, id=post_id)
|
||||
context["max_upload_size"] = settings.MAX_UPLOAD_SIZE
|
||||
print(context["board"])
|
||||
context["capcodes"] = get_objects_for_user(
|
||||
get_user(self.request), "board.use_capcode"
|
||||
)
|
||||
return context
|
||||
|
||||
def get_form_kwargs(self):
|
||||
@@ -129,7 +138,7 @@ class ReplyCreateView(CreateView):
|
||||
post_id = self.kwargs["id"]
|
||||
post = get_object_or_404(Post, id=post_id)
|
||||
kwargs["op"] = post
|
||||
kwargs["reply"] = post
|
||||
kwargs["user"] = self.request.user
|
||||
return kwargs
|
||||
|
||||
|
||||
@@ -154,7 +163,7 @@ class PostView(CreateView):
|
||||
post_id = self.kwargs["id"]
|
||||
post = get_object_or_404(Post, id=post_id)
|
||||
kwargs["op"] = post
|
||||
kwargs["reply"] = post
|
||||
kwargs["user"] = self.request.user
|
||||
return kwargs
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user