feat(backend): platform notifications service with audiences, dedupe, read state and first producers
Platform v2 step 1.11 (APPS_PLATFORM section 10).
- notifications + notification_reads (revision 0010). Text = i18n key notification.<key> + params,
rendered in the reader's language (en, el added).
- core/notifications.py: notify(key, severity, audience, params, dedupe_key, ttl/expires_at, fold)
never raises; audience all_managers | perm:<key> | user:<id>; a live duplicate only bumps
count/last_at (no unread reset, no event). New ones emit WS platform_notification {id} to the
audience's users (current apps ignore it; phase 2 manager shows it).
- API (core, /api/platform/notifications; /api/notifications is chat's): list with unread count,
POST /{id}/read, POST /read-all.
- Producers: license.limit_reached (device pairing/reassign/over-limit device, per module/limit/day,
owners), license.expiring (14/7/3/1 days, from apply_license, owners), support.access_used (each
use, core.settings.manage), print.failed_final (abandoned retry job, per printer/hour, managers).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""notifications + notification_reads (platform notifications)
|
||||
|
||||
Revision ID: 0010_notifications
|
||||
Revises: 0009_support_access
|
||||
Create Date: 2026-11-13 11:06:59.999254
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from core.timeutil import UTCDateTime
|
||||
|
||||
revision = '0010_notifications'
|
||||
down_revision = '0009_support_access'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('notifications',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('key', sa.String(), nullable=False),
|
||||
sa.Column('severity', sa.String(), nullable=False),
|
||||
sa.Column('audience', sa.String(), nullable=False),
|
||||
sa.Column('params', sa.JSON(), nullable=True),
|
||||
sa.Column('dedupe_key', sa.String(), nullable=True),
|
||||
sa.Column('count', sa.Integer(), nullable=False),
|
||||
sa.Column('created_at', UTCDateTime(), nullable=False),
|
||||
sa.Column('last_at', UTCDateTime(), nullable=False),
|
||||
sa.Column('expires_at', UTCDateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sqlite_autoincrement=True
|
||||
)
|
||||
with op.batch_alter_table('notifications', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_notifications_audience'), ['audience'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_notifications_created_at'), ['created_at'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_notifications_dedupe_key'), ['dedupe_key'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_notifications_key'), ['key'], unique=False)
|
||||
|
||||
op.create_table('notification_reads',
|
||||
sa.Column('notification_id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('read_at', UTCDateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('notification_id', 'user_id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('notification_reads')
|
||||
with op.batch_alter_table('notifications', schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f('ix_notifications_key'))
|
||||
batch_op.drop_index(batch_op.f('ix_notifications_dedupe_key'))
|
||||
batch_op.drop_index(batch_op.f('ix_notifications_created_at'))
|
||||
batch_op.drop_index(batch_op.f('ix_notifications_audience'))
|
||||
|
||||
op.drop_table('notifications')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user