diff --git a/app/routes/issues.py b/app/routes/issues.py index c28dd9f..7ee048b 100644 --- a/app/routes/issues.py +++ b/app/routes/issues.py @@ -882,4 +882,39 @@ def quick_assign(issue_id): logger.info('ISSUE QUICK-ASSIGN | issue_id=%s | assigned_to=%s | by=%s', issue.id, label, current_user.username) - return jsonify({'ok': True, 'label': label}) \ No newline at end of file + return jsonify({'ok': True, 'label': label}) + + +# ── Export PDF ──────────────────────────────────────────────────────────────── + +@bp.route('//export-pdf') +@login_required +def export_pdf(issue_id): + from flask import make_response + from app.utils.pdf_export import generate_issue_pdf + from app.utils.audit import ACTION_EXPORT + + issue = db.session.get(Issue, issue_id) + if issue is None: + abort(404) + + if current_user.role == 'inspector': + fids = get_inspector_scope(current_user) + facility = issue.resolved_facility + if not fids or not facility or facility.id not in fids: + abort(403) + if current_user.role == 'customer': + cids = get_customer_scope(current_user) or [] + facility = issue.resolved_facility + if not facility or facility.id not in cids: + abort(403) + + pdf_bytes = generate_issue_pdf(issue, current_app.static_folder) + log_action(ACTION_EXPORT, 'Issue', issue.id, + f'Issue #{issue.id}', + f'PDF export by {current_user.username}') + + resp = make_response(pdf_bytes) + resp.headers['Content-Type'] = 'application/pdf' + resp.headers['Content-Disposition'] = f'attachment; filename="issue_{issue.id}.pdf"' + return resp \ No newline at end of file diff --git a/app/templates/issues/view.html b/app/templates/issues/view.html index d4122c2..932a3b4 100644 --- a/app/templates/issues/view.html +++ b/app/templates/issues/view.html @@ -374,6 +374,9 @@ Back to Issues + + Export PDF + {% if current_user.role in ['admin', 'director'] %}