调整报告公开可访问

This commit is contained in:
mgw
2025-03-17 13:39:59 +08:00
parent db881ac594
commit af529d21ec
2 changed files with 29 additions and 7 deletions

View File

@@ -89,4 +89,26 @@ class QualityController(http.Controller):
('Access-Control-Allow-Methods', 'GET, OPTIONS'),
('Access-Control-Allow-Headers', 'Content-Type, Authorization')
]
)
)
class QualityReportController(http.Controller):
@http.route('/quality/report/<int:attachment_id>', type='http', auth='public')
def get_public_report(self, attachment_id, **kw):
"""提供公开访问PDF报告的控制器"""
attachment = request.env['ir.attachment'].sudo().browse(int(attachment_id))
# 安全检查:确保只有质检报告附件可以被访问
if attachment.exists() and 'QC-' in attachment.name:
# 解码Base64数据为二进制数据
pdf_content = base64.b64decode(attachment.datas)
# 返回解码后的PDF内容
return request.make_response(
pdf_content,
headers=[
('Content-Type', 'application/pdf'),
('Content-Disposition', f'inline; filename={attachment.name}')
]
)
return request.not_found()