05/25 Fix lost inspection's photos after flagging an issue
This commit is contained in:
@@ -499,6 +499,33 @@ def save_draft_ajax(inspection_id):
|
||||
return jsonify({'ok': True})
|
||||
|
||||
|
||||
# ── AJAX: upload a single inspection photo ────────────────────────────────────
|
||||
|
||||
@bp.route('/<int:inspection_id>/upload-photo', methods=['POST'])
|
||||
@login_required
|
||||
def upload_photo_ajax(inspection_id):
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
return jsonify({'ok': False, 'error': 'Not found'}), 404
|
||||
|
||||
if current_user.role == 'inspector' and inspection.inspector_id != current_user.id:
|
||||
return jsonify({'ok': False, 'error': 'Access denied'}), 403
|
||||
|
||||
if inspection.status == 'completed':
|
||||
return jsonify({'ok': False, 'error': 'Inspection already completed'}), 400
|
||||
|
||||
file_obj = request.files.get('photo')
|
||||
path = _save_photo(file_obj, subfolder='inspection_photos')
|
||||
if not path:
|
||||
return jsonify({'ok': False, 'error': 'Invalid file or unsupported format'}), 400
|
||||
|
||||
current_app.logger.info(
|
||||
'INSPECTION PHOTO UPLOADED (AJAX) | inspection_id=%s | path=%s | by=%s',
|
||||
inspection_id, path, current_user.username
|
||||
)
|
||||
return jsonify({'ok': True, 'path': path})
|
||||
|
||||
|
||||
# ── View ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
@bp.route('/<int:inspection_id>')
|
||||
|
||||
Reference in New Issue
Block a user