Use random string ids for reports

This commit is contained in:
rubenwardy
2025-08-26 15:26:07 +01:00
parent e4c061858e
commit 8db72faf3c
3 changed files with 37 additions and 4 deletions

View File

@@ -25,7 +25,7 @@ from wtforms.validators import InputRequired, Length, Optional
from app.models import User, UserRank, Report, db, AuditSeverity, Thread
from app.tasks.webhooktasks import post_discord_webhook
from app.utils import is_no, abs_url_samesite, normalize_line_endings, rank_required, add_audit_log, abs_url_for, \
add_replies
add_replies, random_string
bp = Blueprint("report", __name__)
@@ -55,6 +55,7 @@ def report():
if form and form.validate_on_submit():
report = Report()
report.id = random_string(8)
report.user = current_user if current_user.is_authenticated else None
form.populate_obj(report)
@@ -98,9 +99,9 @@ class ResolveForm(FlaskForm):
invalid = SubmitField(lazy_gettext("Invalid / No action taken"))
@bp.route("/admin/reports/<int:rid>/", methods=["GET", "POST"])
@bp.route("/admin/reports/<rid>/", methods=["GET", "POST"])
@rank_required(UserRank.MODERATOR)
def view(rid: int):
def view(rid: str):
report = Report.query.get_or_404(rid)
resolve_form = ResolveForm(request.form)

View File

@@ -131,7 +131,7 @@ class AuditLogEntry(db.Model):
class Report(db.Model):
id = db.Column(db.Integer, primary_key=True)
id = db.Column(db.String(24), primary_key=True)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)

View File

@@ -0,0 +1,32 @@
"""empty message
Revision ID: 9689a71efe88
Revises: 3052712496e4
Create Date: 2025-08-26 14:24:02.045713
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '9689a71efe88'
down_revision = '3052712496e4'
branch_labels = None
depends_on = None
def upgrade():
with op.batch_alter_table('report', schema=None) as batch_op:
batch_op.alter_column('id',
existing_type=sa.INTEGER(),
type_=sa.String(length=24),
existing_nullable=False)
def downgrade():
with op.batch_alter_table('report', schema=None) as batch_op:
batch_op.alter_column('id',
existing_type=sa.String(length=24),
type_=sa.INTEGER(),
existing_nullable=False)