ban posts or comments

This commit is contained in:
rimu 2024-12-02 13:48:10 +13:00
parent 5c8a14007f
commit 654829cbae
3 changed files with 42 additions and 0 deletions

View file

@ -659,6 +659,8 @@ class User(UserMixin, db.Model):
verification_token = db.Column(db.String(16), index=True)
banned = db.Column(db.Boolean, default=False, index=True)
banned_until = db.Column(db.DateTime) # null == permanent ban
ban_posts = db.Column(db.Boolean, default=False)
ban_comments = db.Column(db.Boolean, default=False)
deleted = db.Column(db.Boolean, default=False)
deleted_by = db.Column(db.Integer, index=True)
about = db.Column(db.Text) # markdown

View file

@ -711,6 +711,9 @@ def can_create_post(user, content: Community) -> bool:
if user is None or content is None or user.banned:
return False
if user.ban_posts:
return False
if content.is_moderator(user) or user.is_admin():
return True
@ -730,6 +733,9 @@ def can_create_post_reply(user, content: Community) -> bool:
if user is None or content is None or user.banned:
return False
if user.ban_comments:
return False
if content.is_moderator(user) or user.is_admin():
return True

View file

@ -0,0 +1,34 @@
"""ban comments
Revision ID: 98680738ebb0
Revises: 20a3bae71dd7
Create Date: 2024-12-02 13:46:32.356061
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '98680738ebb0'
down_revision = '20a3bae71dd7'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('ban_posts', sa.Boolean(), nullable=True))
batch_op.add_column(sa.Column('ban_comments', sa.Boolean(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('ban_comments')
batch_op.drop_column('ban_posts')
# ### end Alembic commands ###