mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 22:40:31 -04:00
Add virus scan stage when uploading a letter
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import uuid
|
||||
from io import BytesIO
|
||||
|
||||
from flask import redirect, render_template, request, url_for
|
||||
from flask import flash, redirect, render_template, request, url_for
|
||||
|
||||
from app import current_service
|
||||
from app.extensions import antivirus_client
|
||||
from app.main import main
|
||||
from app.main.forms import PDFUploadForm
|
||||
from app.utils import user_has_permissions
|
||||
@@ -20,6 +22,13 @@ def upload_letter(service_id):
|
||||
form = PDFUploadForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
pdf_file_bytes = form.file.data.read()
|
||||
|
||||
virus_free = antivirus_client.scan(BytesIO(pdf_file_bytes))
|
||||
if not virus_free:
|
||||
flash('Your file has failed the virus check', 'dangerous')
|
||||
return render_template('views/uploads/choose-file.html', form=form), 400
|
||||
|
||||
upload_id = uuid.uuid4()
|
||||
|
||||
return redirect(
|
||||
|
||||
Reference in New Issue
Block a user