06/11 Add export PDF button to export issue
This commit is contained in:
+36
-1
@@ -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})
|
||||
return jsonify({'ok': True, 'label': label})
|
||||
|
||||
|
||||
# ── Export PDF ────────────────────────────────────────────────────────────────
|
||||
|
||||
@bp.route('/<int:issue_id>/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
|
||||
Reference in New Issue
Block a user