Jul 16 - Update submission will trigger notification to self inspector only
This commit is contained in:
@@ -569,6 +569,20 @@ def notify_by_matrix(
|
||||
logger.info('MATRIX NOTIFY | event=%s | role=%s | users_found=%s',
|
||||
event_type, role_key, [u.username for u in users])
|
||||
|
||||
# Scope the inspector role for "inspection_completed" to the inspection's
|
||||
# OWN inspector (the person who did the work), not the whole inspector
|
||||
# pool. Without this, enabling the Inspector column for this event would
|
||||
# notify every inspector on every submission.
|
||||
if role_key == 'inspector' and event_type == 'inspection_completed':
|
||||
target_id = None
|
||||
if inspection_id:
|
||||
from app.models.inspection import Inspection
|
||||
insp = db.session.get(Inspection, inspection_id)
|
||||
target_id = insp.inspector_id if insp else None
|
||||
users = [u for u in users if u.id == target_id] if target_id else []
|
||||
logger.info('MATRIX NOTIFY | event=%s | role=inspector scoped to '
|
||||
'submitting inspector_id=%s', event_type, target_id)
|
||||
|
||||
# Scope customer role to facility if provided
|
||||
if role_key == 'customer' and facility_id:
|
||||
from app.utils.notifications import notify_customers_for_facility
|
||||
|
||||
Reference in New Issue
Block a user