04/27 Fixed notification hasn't been sent when submitting inspection
This commit is contained in:
@@ -171,6 +171,7 @@ def notify(
|
||||
inspection_id: int = None,
|
||||
event_type: str = None,
|
||||
send_email: bool = True,
|
||||
respect_preferences: bool = True,
|
||||
):
|
||||
"""Create an in-app Notification record and optionally send an email.
|
||||
|
||||
@@ -185,9 +186,18 @@ def notify(
|
||||
event_type : One of the EVENT_* constants from models.notification
|
||||
Used to look up the user's preference for this event.
|
||||
send_email : Master switch — set False to suppress all email (overrides prefs)
|
||||
respect_preferences : When True (default), per-user email preferences gate delivery.
|
||||
Set False for matrix-routed broadcasts — the matrix is the
|
||||
authority; individual opt-out should not override admin config.
|
||||
"""
|
||||
# Determine digest flag before creating the record
|
||||
hold_for_digest = send_email and bool(event_type) and _digest_mode_for(recipient, event_type)
|
||||
# Determine digest flag before creating the record.
|
||||
# Digest mode is only respected when individual preferences are in effect.
|
||||
hold_for_digest = (
|
||||
respect_preferences
|
||||
and send_email
|
||||
and bool(event_type)
|
||||
and _digest_mode_for(recipient, event_type)
|
||||
)
|
||||
|
||||
# ── 1. Persist in-app notification ──────────────────────────────────────
|
||||
notif = Notification(
|
||||
@@ -210,9 +220,18 @@ def notify(
|
||||
|
||||
# ── 2. Send immediate email if applicable ────────────────────────────────
|
||||
if send_email and not hold_for_digest:
|
||||
if respect_preferences:
|
||||
# Per-user opt-in/opt-out gate — used for direct notifications
|
||||
# (issue assignment, SLA alerts, follower updates, etc.)
|
||||
should_send = (
|
||||
event_type is None or _email_enabled_for(recipient, event_type)
|
||||
)
|
||||
else:
|
||||
# Matrix-routed broadcast — the admin matrix is the authority.
|
||||
# Individual preference rows must not override it, otherwise an
|
||||
# admin or director who once clicked "Pause All" would silently
|
||||
# stop receiving inspection completion and other broadcast events.
|
||||
should_send = True
|
||||
if should_send and recipient.email and current_app.config.get('MAIL_SERVER'):
|
||||
_send_single_email(recipient, title, body, link)
|
||||
|
||||
@@ -555,6 +574,7 @@ def notify_by_matrix(
|
||||
inspection_id = inspection_id,
|
||||
event_type = event_type,
|
||||
send_email = True,
|
||||
respect_preferences = False, # matrix is the authority for broadcasts
|
||||
)
|
||||
notified.add(user.id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user