diff --git a/board/forms.py b/board/forms.py index bb4b557..55fef39 100644 --- a/board/forms.py +++ b/board/forms.py @@ -4,6 +4,7 @@ from django.db import transaction from django.db.models import Q from django import forms from django.forms import ModelForm, ModelChoiceField +from django.forms.models import fields_for_model from django.utils import timezone from board.models import Ban, Post, Report, ReportReason, ReportRecord from hcaptcha.fields import hCaptchaField @@ -124,8 +125,23 @@ class PostModifyForm(ModelForm): class Meta: model = Post - fields = ["bump", "sticky"] + # we specify fields up here too because otherwise they won't be + # recognized by the form to update values + fields: list[str] = ["sticky"] - def clean(self): - super(PostModifyForm, self).clean() - print(self.fields["sticky"]) + def __init__(self, *args, user, **kwargs): + super(PostModifyForm, self).__init__(*args, **kwargs) + self.user = user + fields = [] + if self.user.has_perm("board.set_sticky"): + fields += ["sticky"] + # 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 + # malicious actor has access to the modify form and injects a "sticky" + # value to their modify request. + # + # We specify fields up in the Meta class, but we reset them down here. + # If the field isn't present in this list, then it doesn't get updated. + # If the field isn't present in the above list, then it doesn't get updated. + self.fields = fields_for_model(Post, fields) diff --git a/board/templates/board/base.html b/board/templates/board/base.html index 30b9b68..0160acd 100644 --- a/board/templates/board/base.html +++ b/board/templates/board/base.html @@ -12,8 +12,11 @@ - {% if perms.board.create_ban %} - + {% if perms.board.add_ban %} + + {% endif %} + {% if can_modify %} + {% endif %} {% block extrajs %}{% endblock %} diff --git a/board/templates/board/post_modify_success.html b/board/templates/board/post_modify_success.html new file mode 100644 index 0000000..d79b679 --- /dev/null +++ b/board/templates/board/post_modify_success.html @@ -0,0 +1,33 @@ +{% extends "board/base.html" %} +{% load i18n static %} +{# Title #} +{% block title %}{% translate "Post modify success" %}{% endblock %} +{# Body #} +{% block content %} +