Add user bug reporting with admin triage (open/read/resolved)
Turns the /report-bug placeholder into a real form (POST /bug-reports, optionally attributed to the logged-in user) and adds a "Segnalazioni bug" section to /admin to view and triage them. A logged-in reporter can also check their own report's status via GET /bug-reports/mine, since anonymous submissions have no user to show a history to. Status is a three-state lifecycle (open -> read -> resolved) rather than a plain boolean, so an admin can acknowledge a report distinctly from actually fixing it. The schema went through two migrations because the first one (add bug_reports table) had already been applied against the running instance with a `resolved` boolean before the three-state design was decided, so a follow-up migration backfills it into `status` instead of rewriting already-applied history. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""replace bug_reports.resolved with a three-state status
|
||||
|
||||
Revision ID: be71fdac734e
|
||||
Revises: ee8508d98d34
|
||||
Create Date: 2026-07-31 15:33:51.780062
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'be71fdac734e'
|
||||
down_revision: Union[str, Sequence[str], None] = 'ee8508d98d34'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema, preserving existing rows: resolved=True -> 'resolved', else 'open'.
|
||||
|
||||
'read' has no equivalent in the old boolean, so nothing backfills into it —
|
||||
every previously-open report starts the new lifecycle at 'open', which is
|
||||
correct (nobody had acknowledged it yet)."""
|
||||
op.add_column('bug_reports', sa.Column('status', sa.String(length=16), nullable=True))
|
||||
op.execute("UPDATE bug_reports SET status = CASE WHEN resolved THEN 'resolved' ELSE 'open' END")
|
||||
with op.batch_alter_table('bug_reports') as batch_op:
|
||||
batch_op.alter_column('status', nullable=False)
|
||||
batch_op.drop_column('resolved')
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema. 'read' collapses back into resolved=False — the same loss
|
||||
of information any boolean-from-enum downgrade has."""
|
||||
op.add_column('bug_reports', sa.Column('resolved', sa.BOOLEAN(), nullable=True))
|
||||
op.execute("UPDATE bug_reports SET resolved = (status = 'resolved')")
|
||||
with op.batch_alter_table('bug_reports') as batch_op:
|
||||
batch_op.alter_column('resolved', nullable=False)
|
||||
batch_op.drop_column('status')
|
||||
@@ -0,0 +1,41 @@
|
||||
"""add bug_reports table
|
||||
|
||||
Revision ID: ee8508d98d34
|
||||
Revises: 87a0c640355c
|
||||
Create Date: 2026-07-31 15:14:14.288552
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'ee8508d98d34'
|
||||
down_revision: Union[str, Sequence[str], None] = '87a0c640355c'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('bug_reports',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('description', sa.Text(), nullable=False),
|
||||
sa.Column('contact', sa.String(length=256), nullable=True),
|
||||
sa.Column('user_id', sa.Integer(), nullable=True),
|
||||
sa.Column('resolved', sa.Boolean(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('bug_reports')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user