Use full FQDN for device name and fix machine URL

- Get pc_access_domain from settings to build full FQDN (hostname.device.geaerospace.net)
- Display FQDN in email subject and body instead of short hostname
- Fix machine_url to use actual request host instead of localhost fallback
- Remove unnecessary try-except around machine URL construction
This commit is contained in:
Proudlock
2026-09-09 10:03:26 -04:00
parent 18e21a87d0
commit 2090c0d4ef

View File

@@ -3000,7 +3000,19 @@ def _send_operator_report_alert(report, asset_id, hostname):
except Exception as e:
current_app.logger.warning('Failed to generate screenshot URL: %s', e)
# Get PC access domain to build FQDN
from shopdb.core.models import Setting
pc_access_domain_setting = Setting.query.filter_by(key='pc_access_domain').first()
pc_access_domain = pc_access_domain_setting.value if pc_access_domain_setting else ''
# Build full FQDN
if pc_access_domain and not hostname.endswith(pc_access_domain):
fqdn = f'{hostname}.{pc_access_domain}'
else:
fqdn = hostname
# HTML-escape all user-controlled values to prevent XSS
safe_fqdn = escape(fqdn)
safe_hostname = escape(hostname)
safe_name = escape(asset.name or hostname)
safe_assetnumber = escape(asset.assetnumber or 'N/A')
@@ -3012,12 +3024,9 @@ def _send_operator_report_alert(report, asset_id, hostname):
machine_body_line = ''
if machine_info:
safe_machine_number = escape(machine_info['assetnumber'] or 'N/A')
try:
scheme = request.scheme if request else 'https'
host = request.host if request else 'localhost'
machine_url = f'{scheme}://{host}/shopdb/machines/{machine_info["assetid"]}'
except Exception:
machine_url = f'https://localhost/shopdb/machines/{machine_info["assetid"]}'
scheme = request.scheme if request else 'https'
host = request.host if request else 'localhost'
machine_url = f'{scheme}://{host}/shopdb/machines/{machine_info["assetid"]}'
machine_subject_part = f' (Machine #{safe_machine_number})'
machine_body_line = f'<p style="margin: 0;"><strong>Machine#:</strong> <a href="{escape(machine_url)}">{safe_machine_number}</a></p>'
@@ -3028,7 +3037,7 @@ def _send_operator_report_alert(report, asset_id, hostname):
<h2 style="color:#1a1a1a;margin:0 0 12px;">Operator Issue Report</h2>
<div style="padding: 16px; background: #f9f9f9; border-left: 4px solid #d93f3f; margin-bottom: 16px;">
<p style="margin: 0 0 8px; font-weight: bold; color: #d93f3f;">New Issue Report from Shop Floor</p>
<p style="margin: 0;"><strong>Device:</strong> <a href="{escape(device_url)}">{safe_hostname}</a></p>
<p style="margin: 0;"><strong>Device:</strong> <a href="{escape(device_url)}">{safe_fqdn}</a></p>
{machine_body_line}
<p style="margin: 0;"><strong>Reason:</strong> {safe_reason}</p>
<p style="margin: 0;"><strong>Reported:</strong> {escape(reported_at)}</p>
@@ -3042,7 +3051,7 @@ def _send_operator_report_alert(report, asset_id, hostname):
</div>
'''
subject = f'Operator Issue Report: {safe_hostname}{machine_subject_part}'
subject = f'Operator Issue Report: {safe_fqdn}{machine_subject_part}'
current_app.logger.info('Sending operator report alert for %s (report %d)',
hostname, report.operatorreportid)