06/23 Implement broadcast function for admin

This commit is contained in:
Nguyen Ngo
2026-06-23 18:55:53 -04:00
parent ed74e5064c
commit 056690e6da
7 changed files with 366 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
# app/models/broadcast.py
# -----------------------
# Stores admin-sent broadcast notification records.
# Each broadcast creates one Notification row per targeted user —
# the iOS app receives them via its existing poll cycle
# (GET /api/v1/notifications?since=...) with no new API endpoint required.
from app import db
from app.utils.time_utils import now_eastern
class Broadcast(db.Model):
__tablename__ = 'broadcasts'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(255), nullable=False)
body = db.Column(db.Text, nullable=False)
# JSON-encoded list of role strings targeted, e.g. '["inspector","project_manager"]'
target_roles = db.Column(db.JSON, nullable=False, default=list)
sent_by_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='SET NULL'), nullable=True)
sent_at = db.Column(db.DateTime, default=now_eastern, nullable=False)
# Number of Notification rows created (resolved at send time)
recipient_count = db.Column(db.Integer, default=0, nullable=False)
sent_by = db.relationship('User', foreign_keys=[sent_by_id])
def __repr__(self):
return f'<Broadcast {self.id} "{self.title[:30]}" roles={self.target_roles}>'
+3
View File
@@ -27,6 +27,8 @@ EVENT_CUSTOMER_ISSUE_UPDATED = 'customer_issue_updated'
# more than the configured threshold vs. the prior period.
EVENT_SCORE_ALERT = 'score_alert'
EVENT_ADMIN_BROADCAST = 'admin_broadcast' # bulk messages sent by admin to all apps
ALL_EVENT_TYPES = {
EVENT_ISSUE_ASSIGNED: 'Issue assigned to me',
EVENT_ISSUE_STATUS: 'Issue status changed',
@@ -35,6 +37,7 @@ ALL_EVENT_TYPES = {
EVENT_ISSUE_FLAGGED: 'Issue flagged (from inspection)',
EVENT_INSPECTION_DONE: 'Inspection completed',
EVENT_SLA_ALERT: 'SLA at-risk / breached alerts',
EVENT_ADMIN_BROADCAST: 'Admin broadcast (system announcements)',
# Customer-facing — only relevant for customer role accounts
EVENT_CUSTOMER_INSPECTION_DONE: 'Inspection completed at my facility (portal)',
EVENT_CUSTOMER_ISSUE_UPDATED: 'Issue created or updated at my facility (portal)',