diff --git a/app/models.py b/app/models.py index 8f0d0945..6f0c5ada 100644 --- a/app/models.py +++ b/app/models.py @@ -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 diff --git a/app/utils.py b/app/utils.py index 73c79673..26cdc9ee 100644 --- a/app/utils.py +++ b/app/utils.py @@ -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 diff --git a/migrations/versions/98680738ebb0_ban_comments.py b/migrations/versions/98680738ebb0_ban_comments.py new file mode 100644 index 00000000..803a8529 --- /dev/null +++ b/migrations/versions/98680738ebb0_ban_comments.py @@ -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 ###