From 6e497a47517775584d9dcc63548c9ce19e6e61ed Mon Sep 17 00:00:00 2001 From: Proudlock <270015376@geaerospace.com> Date: Wed, 9 Sep 2026 09:02:43 -0400 Subject: [PATCH] Fix operator report email alerts with proper template and logging - Use render_email() to wrap HTML in proper email template - Add error handling and logging for URL generation - Add log statement before sending to aid debugging - Import render_email at module level --- plugins/endpoints/api/routes.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/endpoints/api/routes.py b/plugins/endpoints/api/routes.py index 9f9fff9d..533ba1a4 100644 --- a/plugins/endpoints/api/routes.py +++ b/plugins/endpoints/api/routes.py @@ -32,7 +32,7 @@ from ..models import ( ) from ..commands import COMMAND_ALLOWLIST, is_allowed_action, ALLOWED_ACTIONS_FOR, row_actions_for, requires_target, action_targetkind, elevated_permission_for, PLACE_POLICY_HOLD, ACTIVE_POLICY_HOLDS, HOLDABLE_ACTIONS_FOR, RELEASE_POLICY_HOLD, ACTIVE_LOCK_FOR, PLACE_ENDPOINT_LOCK, RELEASE_ENDPOINT_LOCK from ..eventcatalog import CRITICAL_EVENT_IDS, event_severity, event_title -from shopdb.utils.mailer import send_alert +from shopdb.utils.mailer import send_alert, render_email endpoints_bp = Blueprint('endpoints', __name__) @@ -2942,21 +2942,30 @@ def _send_operator_report_alert(report, asset_id, hostname): asset = Asset.query.get(asset_id) if not asset: + current_app.logger.warning('Cannot send operator report alert: asset %d not found', asset_id) return - device_url = url_for('assets.detail', asset_id=asset_id, _external=True) + try: + device_url = url_for('assets.detail', asset_id=asset_id, _external=True) + except Exception as e: + current_app.logger.error('Failed to generate device URL: %s', e) + device_url = f'/shopdb/assets/{asset_id}' + reported_at = report.createdat.strftime('%Y-%m-%d %H:%M:%S UTC') if report.createdat else 'Unknown' screenshot_info = '' if report.imagefilename: - screenshot_url = url_for('endpoints.serve_operator_report_image', - operatorreportid=report.operatorreportid, - _external=True) - screenshot_info = f'

Screenshot: View Screenshot

' + try: + screenshot_url = url_for('endpoints.serve_operator_report_image', + operatorreportid=report.operatorreportid, + _external=True) + screenshot_info = f'

Screenshot: View Screenshot

' + except Exception as e: + current_app.logger.warning('Failed to generate screenshot URL: %s', e) details_html = f'

{report.details or "No additional details provided."}

' - html_body = f''' + body_html = f'''

New Issue Report from Shop Floor

Device: {asset.computername or hostname} ({hostname})

@@ -2971,8 +2980,11 @@ def _send_operator_report_alert(report, asset_id, hostname): ''' subject = f'Operator Issue Report: {asset.computername or hostname}' + html, text = render_email(subject, body_html) - send_alert(subject, html_body) + current_app.logger.info('Sending operator report alert for %s (report %d)', + hostname, report.operatorreportid) + send_alert(subject, html, text=text) @endpoints_bp.route('/operatorreports', methods=['POST'])