mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
delete a variety of pdf-related things
This commit is contained in:
@@ -49,11 +49,6 @@ class ValidationError(InvalidRequest):
|
||||
self.message = message if message else self.message
|
||||
|
||||
|
||||
class PDFNotReadyError(BadRequestError):
|
||||
def __init__(self):
|
||||
super().__init__(message='PDF not available yet, try again later', status_code=400)
|
||||
|
||||
|
||||
def register_errors(blueprint):
|
||||
@blueprint.errorhandler(InvalidEmailError)
|
||||
def invalid_format(error):
|
||||
|
||||
@@ -1,18 +1,8 @@
|
||||
from io import BytesIO
|
||||
|
||||
from flask import current_app, jsonify, request, send_file, url_for
|
||||
from flask import current_app, jsonify, request, url_for
|
||||
|
||||
from app import api_user, authenticated_service
|
||||
from app.dao import notifications_dao
|
||||
from app.letters.utils import get_letter_pdf_and_metadata
|
||||
from app.models import (
|
||||
LETTER_TYPE,
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_VIRUS_SCAN_FAILED,
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.v2.errors import BadRequestError, PDFNotReadyError
|
||||
from app.v2.notifications import v2_notification_blueprint
|
||||
from app.v2.notifications.notification_schemas import (
|
||||
get_notifications_request,
|
||||
@@ -30,32 +20,33 @@ def get_notification_by_id(notification_id):
|
||||
return jsonify(notification.serialize()), 200
|
||||
|
||||
|
||||
@v2_notification_blueprint.route('/<notification_id>/pdf', methods=['GET'])
|
||||
def get_pdf_for_notification(notification_id):
|
||||
_data = {"notification_id": notification_id}
|
||||
validate(_data, notification_by_id)
|
||||
notification = notifications_dao.get_notification_by_id(
|
||||
notification_id, authenticated_service.id, _raise=True
|
||||
)
|
||||
# TODO: return deprecation notice
|
||||
# @v2_notification_blueprint.route('/<notification_id>/pdf', methods=['GET'])
|
||||
# def get_pdf_for_notification(notification_id):
|
||||
# _data = {"notification_id": notification_id}
|
||||
# validate(_data, notification_by_id)
|
||||
# notification = notifications_dao.get_notification_by_id(
|
||||
# notification_id, authenticated_service.id, _raise=True
|
||||
# )
|
||||
|
||||
if notification.notification_type != LETTER_TYPE:
|
||||
raise BadRequestError(message="Notification is not a letter")
|
||||
# if notification.notification_type != LETTER_TYPE:
|
||||
# raise BadRequestError(message="Notification is not a letter")
|
||||
|
||||
if notification.status == NOTIFICATION_VIRUS_SCAN_FAILED:
|
||||
raise BadRequestError(message='File did not pass the virus scan')
|
||||
# if notification.status == NOTIFICATION_VIRUS_SCAN_FAILED:
|
||||
# raise BadRequestError(message='File did not pass the virus scan')
|
||||
|
||||
if notification.status == NOTIFICATION_TECHNICAL_FAILURE:
|
||||
raise BadRequestError(message='PDF not available for letters in status {}'.format(notification.status))
|
||||
# if notification.status == NOTIFICATION_TECHNICAL_FAILURE:
|
||||
# raise BadRequestError(message='PDF not available for letters in status {}'.format(notification.status))
|
||||
|
||||
if notification.status == NOTIFICATION_PENDING_VIRUS_CHECK:
|
||||
raise PDFNotReadyError()
|
||||
# if notification.status == NOTIFICATION_PENDING_VIRUS_CHECK:
|
||||
# raise PDFNotReadyError()
|
||||
|
||||
try:
|
||||
pdf_data, metadata = get_letter_pdf_and_metadata(notification)
|
||||
except Exception:
|
||||
raise PDFNotReadyError()
|
||||
# try:
|
||||
# pdf_data, metadata = get_letter_pdf_and_metadata(notification)
|
||||
# except Exception:
|
||||
# raise PDFNotReadyError()
|
||||
|
||||
return send_file(path_or_file=BytesIO(pdf_data), mimetype='application/pdf')
|
||||
# return send_file(path_or_file=BytesIO(pdf_data), mimetype='application/pdf')
|
||||
|
||||
|
||||
@v2_notification_blueprint.route("", methods=['GET'])
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import base64
|
||||
import functools
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
@@ -13,13 +12,10 @@ from app import (
|
||||
authenticated_service,
|
||||
document_download_client,
|
||||
encryption,
|
||||
notify_celery,
|
||||
)
|
||||
from app.celery.tasks import save_api_email, save_api_sms
|
||||
from app.clients.document_download import DocumentDownloadError
|
||||
from app.config import QueueNames, TaskNames
|
||||
from app.dao.dao_utils import transaction
|
||||
from app.letters.utils import upload_letter_pdf
|
||||
from app.config import QueueNames
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
KEY_TYPE_NORMAL,
|
||||
@@ -27,7 +23,6 @@ from app.models import (
|
||||
KEY_TYPE_TEST,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||
NOTIFICATION_SENDING,
|
||||
PRIORITY,
|
||||
SMS_TYPE,
|
||||
@@ -321,6 +316,7 @@ def process_document_uploads(personalisation_data, service, simulated=False):
|
||||
return personalisation_data, len(file_keys)
|
||||
|
||||
|
||||
# TODO: remove precompiled var
|
||||
def process_letter_notification(
|
||||
*, letter_data, api_key, service, template, template_with_content, reply_to_text, precompiled=False
|
||||
):
|
||||
@@ -330,13 +326,6 @@ def process_letter_notification(
|
||||
if not service.research_mode and service.restricted and api_key.key_type != KEY_TYPE_TEST:
|
||||
raise BadRequestError(message='Cannot send letters when service is in trial mode', status_code=403)
|
||||
|
||||
if precompiled:
|
||||
return process_precompiled_letter_notifications(letter_data=letter_data,
|
||||
api_key=api_key,
|
||||
service=service,
|
||||
template=template,
|
||||
reply_to_text=reply_to_text)
|
||||
|
||||
postage = validate_address(service, letter_data['personalisation'])
|
||||
|
||||
test_key = api_key.key_type == KEY_TYPE_TEST
|
||||
@@ -375,40 +364,6 @@ def process_letter_notification(
|
||||
return resp
|
||||
|
||||
|
||||
def process_precompiled_letter_notifications(*, letter_data, api_key, service, template, reply_to_text):
|
||||
try:
|
||||
status = NOTIFICATION_PENDING_VIRUS_CHECK
|
||||
letter_content = base64.b64decode(letter_data['content'])
|
||||
except ValueError:
|
||||
raise BadRequestError(message='Cannot decode letter content (invalid base64 encoding)', status_code=400)
|
||||
|
||||
with transaction():
|
||||
notification = create_letter_notification(letter_data=letter_data,
|
||||
service=service,
|
||||
template=template,
|
||||
api_key=api_key,
|
||||
status=status,
|
||||
reply_to_text=reply_to_text)
|
||||
filename = upload_letter_pdf(notification, letter_content, precompiled=True)
|
||||
|
||||
resp = {
|
||||
'id': notification.id,
|
||||
'reference': notification.client_reference,
|
||||
'postage': notification.postage
|
||||
}
|
||||
|
||||
# call task to add the filename to anti virus queue
|
||||
if current_app.config['ANTIVIRUS_ENABLED']:
|
||||
current_app.logger.info('Calling task scan-file for {}'.format(filename))
|
||||
notify_celery.send_task(
|
||||
name=TaskNames.SCAN_FILE,
|
||||
kwargs={'filename': filename},
|
||||
queue=QueueNames.ANTIVIRUS,
|
||||
)
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
def get_reply_to_text(notification_type, form, template):
|
||||
reply_to = None
|
||||
if notification_type == EMAIL_TYPE:
|
||||
|
||||
Reference in New Issue
Block a user