mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
add flag to return pdf content via api
this is only applicable when getting a single notification by id. it's also ignored if the notification isn't a letter. Otherwise, it overwrites the 'body' field in the response. If the notification's pdf is available, it returns that, base64 encoded. If the pdf is not available, it returns an empty string. The pdf won't be available if the notification's status is: * pending-virus-scan * virus-scan-failed * validation-failed * technical-failure The pdf will be retrieved from the correct s3 bucket based on its type
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import base64
|
||||
|
||||
from flask import jsonify, request, url_for, current_app
|
||||
|
||||
from app import api_user, authenticated_service
|
||||
from app.dao import notifications_dao
|
||||
from app.letters.utils import get_letter_pdf
|
||||
from app.schema_validation import validate
|
||||
from app.v2.notifications import v2_notification_blueprint
|
||||
from app.v2.notifications.notification_schemas import get_notifications_request, notification_by_id
|
||||
from app.models import NOTIFICATION_CREATED, NOTIFICATION_STATUS_TYPES_BILLABLE_FOR_LETTERS, LETTER_TYPE
|
||||
|
||||
|
||||
@v2_notification_blueprint.route("/<notification_id>", methods=['GET'])
|
||||
@@ -14,7 +19,17 @@ def get_notification_by_id(notification_id):
|
||||
authenticated_service.id, notification_id, key_type=None
|
||||
)
|
||||
|
||||
return jsonify(notification.serialize()), 200
|
||||
response = notification.serialize()
|
||||
|
||||
if request.args.get('return_pdf_content') and notification.notification_type == LETTER_TYPE:
|
||||
if notification.status in (NOTIFICATION_CREATED, *NOTIFICATION_STATUS_TYPES_BILLABLE_FOR_LETTERS):
|
||||
pdf_data = get_letter_pdf(notification)
|
||||
else:
|
||||
# precompiled letters that are still being virus scanned, or that failed validation/virus scan
|
||||
pdf_data = b''
|
||||
response['body'] = base64.b64encode(pdf_data).decode('utf-8')
|
||||
|
||||
return jsonify(response), 200
|
||||
|
||||
|
||||
@v2_notification_blueprint.route("", methods=['GET'])
|
||||
|
||||
Reference in New Issue
Block a user