06/18 Fix notification issues
This commit is contained in:
+8
-10
@@ -1,4 +1,4 @@
|
|||||||
"""
|
"""
|
||||||
app/api/issues.py
|
app/api/issues.py
|
||||||
-----------------
|
-----------------
|
||||||
Mobile API endpoint for submitting issues from the iPad app.
|
Mobile API endpoint for submitting issues from the iPad app.
|
||||||
@@ -249,7 +249,7 @@ def create_issue():
|
|||||||
mobile_local_id = mobile_local_id,
|
mobile_local_id = mobile_local_id,
|
||||||
)
|
)
|
||||||
db.session.add(issue)
|
db.session.add(issue)
|
||||||
db.session.flush() # get issue.id
|
db.session.commit() # commit issue first so FK references in notifications are valid
|
||||||
|
|
||||||
# ── Notifications ─────────────────────────────────────────────────────
|
# ── Notifications ─────────────────────────────────────────────────────
|
||||||
try:
|
try:
|
||||||
@@ -260,20 +260,18 @@ def create_issue():
|
|||||||
|
|
||||||
inspection_ref = f'inspection #{inspection_id}' if inspection_id else 'a standalone report'
|
inspection_ref = f'inspection #{inspection_id}' if inspection_id else 'a standalone report'
|
||||||
notify_by_matrix(
|
notify_by_matrix(
|
||||||
event_type = 'issue_flagged',
|
event_type = 'issue_created',
|
||||||
title = f'New Issue #{issue.id} (Mobile)',
|
title = f'New Issue #{issue.id} at {facility.name} (Mobile)',
|
||||||
body = (
|
body = (
|
||||||
f'A new {severity.title()}-severity issue was logged at '
|
f'A new {severity.title()}-severity issue was logged at '
|
||||||
f'{facility.name} during {inspection_ref}. '
|
f'{facility.name} during {inspection_ref}. '
|
||||||
f'Description: {description[:120]}'
|
f'Description: {description[:120]}'
|
||||||
f'{"…" if len(description) > 120 else ""}'
|
f'{"…" if len(description) > 120 else ""}'
|
||||||
),
|
),
|
||||||
link = issue_link,
|
link = issue_link,
|
||||||
issue_id = issue.id,
|
issue_id = issue.id,
|
||||||
facility_id = facility_id,
|
facility_id = facility_id,
|
||||||
exclude_user_ids = {user.id},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
log_action(ACTION_CREATE, 'Issue', issue.id,
|
log_action(ACTION_CREATE, 'Issue', issue.id,
|
||||||
|
|||||||
@@ -727,21 +727,22 @@ def create():
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# ── Notify via matrix (issue_created) ────────────────────────
|
# ── Notify via matrix (issue_created) ────────────────────────
|
||||||
|
# No exclude_user_ids: the creator should also receive the in-app
|
||||||
|
# confirmation so they see it in their notification feed.
|
||||||
facility = issue.resolved_facility
|
facility = issue.resolved_facility
|
||||||
if facility:
|
if facility:
|
||||||
notify_by_matrix(
|
notify_by_matrix(
|
||||||
event_type = 'issue_created',
|
event_type = 'issue_created',
|
||||||
title = f'New Issue #{issue.id} at {facility.name}',
|
title = f'New Issue #{issue.id} at {facility.name}',
|
||||||
body = (
|
body = (
|
||||||
f'A new {issue.severity.title()}-severity issue has been logged '
|
f'A new {issue.severity.title()}-severity issue has been logged '
|
||||||
f'at {facility.name}. '
|
f'at {facility.name}. '
|
||||||
f'Description: {issue.description[:120]}'
|
f'Description: {issue.description[:120]}'
|
||||||
f'{"…" if len(issue.description) > 120 else ""}'
|
f'{"…" if len(issue.description) > 120 else ""}'
|
||||||
),
|
),
|
||||||
link = url_for('issues.view', issue_id=issue.id),
|
link = url_for('issues.view', issue_id=issue.id),
|
||||||
issue_id = issue.id,
|
issue_id = issue.id,
|
||||||
facility_id = facility.id,
|
facility_id = facility.id,
|
||||||
exclude_user_ids = {current_user.id},
|
|
||||||
)
|
)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Issue created.', 'success')
|
flash('Issue created.', 'success')
|
||||||
|
|||||||
Reference in New Issue
Block a user