mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-27 11:19:56 -04:00
carving out precompile, almost completely
This commit is contained in:
@@ -156,7 +156,7 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days(service_
|
||||
query = db.session.query(
|
||||
*([
|
||||
Template.name.label("template_name"),
|
||||
Template.is_precompiled_letter,
|
||||
False, # TODO: this is related to is_precompiled_letter
|
||||
all_stats_table.c.template_id
|
||||
] if by_template else []),
|
||||
all_stats_table.c.notification_type,
|
||||
@@ -168,7 +168,7 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days(service_
|
||||
query = query.filter(all_stats_table.c.template_id == Template.id)
|
||||
|
||||
return query.group_by(
|
||||
*([Template.name, Template.is_precompiled_letter, all_stats_table.c.template_id] if by_template else []),
|
||||
*([Template.name, all_stats_table.c.template_id] if by_template else []),
|
||||
all_stats_table.c.notification_type,
|
||||
all_stats_table.c.status,
|
||||
).all()
|
||||
@@ -333,7 +333,6 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
||||
FactNotificationStatus.template_id.label('template_id'),
|
||||
Template.name.label('name'),
|
||||
Template.template_type.label('template_type'),
|
||||
Template.is_precompiled_letter.label('is_precompiled_letter'),
|
||||
extract('month', FactNotificationStatus.local_date).label('month'),
|
||||
extract('year', FactNotificationStatus.local_date).label('year'),
|
||||
func.sum(FactNotificationStatus.notification_count).label('count')
|
||||
@@ -349,7 +348,6 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
||||
FactNotificationStatus.template_id,
|
||||
Template.name,
|
||||
Template.template_type,
|
||||
Template.is_precompiled_letter,
|
||||
extract('month', FactNotificationStatus.local_date).label('month'),
|
||||
extract('year', FactNotificationStatus.local_date).label('year'),
|
||||
).order_by(
|
||||
@@ -366,7 +364,6 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
||||
Notification.template_id.label('template_id'),
|
||||
Template.name.label('name'),
|
||||
Template.template_type.label('template_type'),
|
||||
Template.is_precompiled_letter.label('is_precompiled_letter'),
|
||||
extract('month', month).label('month'),
|
||||
extract('year', month).label('year'),
|
||||
func.count().label('count')
|
||||
@@ -389,7 +386,6 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
||||
query = db.session.query(
|
||||
all_stats_table.c.template_id,
|
||||
all_stats_table.c.name,
|
||||
all_stats_table.c.is_precompiled_letter,
|
||||
all_stats_table.c.template_type,
|
||||
func.cast(all_stats_table.c.month, Integer).label('month'),
|
||||
func.cast(all_stats_table.c.year, Integer).label('year'),
|
||||
@@ -397,7 +393,6 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
||||
).group_by(
|
||||
all_stats_table.c.template_id,
|
||||
all_stats_table.c.name,
|
||||
all_stats_table.c.is_precompiled_letter,
|
||||
all_stats_table.c.template_type,
|
||||
all_stats_table.c.month,
|
||||
all_stats_table.c.year,
|
||||
|
||||
@@ -30,7 +30,6 @@ from sqlalchemy import (
|
||||
from sqlalchemy.dialects.postgresql import JSON, JSONB, UUID
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.orm import validates
|
||||
from sqlalchemy.orm.collections import attribute_mapped_collection
|
||||
|
||||
@@ -296,7 +295,6 @@ INTERNATIONAL_SMS_TYPE = 'international_sms'
|
||||
INBOUND_SMS_TYPE = 'inbound_sms'
|
||||
SCHEDULE_NOTIFICATIONS = 'schedule_notifications'
|
||||
EMAIL_AUTH = 'email_auth'
|
||||
PRECOMPILED_LETTER = 'precompiled_letter'
|
||||
UPLOAD_DOCUMENT = 'upload_document'
|
||||
EDIT_FOLDER_PERMISSIONS = 'edit_folder_permissions'
|
||||
UPLOAD_LETTERS = 'upload_letters'
|
||||
@@ -880,9 +878,6 @@ template_folder_map = db.Table(
|
||||
)
|
||||
|
||||
|
||||
PRECOMPILED_TEMPLATE_NAME = 'Pre-compiled PDF'
|
||||
|
||||
|
||||
class TemplateBase(db.Model):
|
||||
__abstract__ = True
|
||||
|
||||
@@ -960,14 +955,6 @@ class TemplateBase(db.Model):
|
||||
else:
|
||||
return None
|
||||
|
||||
@hybrid_property
|
||||
def is_precompiled_letter(self):
|
||||
return self.hidden and self.name == PRECOMPILED_TEMPLATE_NAME and self.template_type == LETTER_TYPE
|
||||
|
||||
@is_precompiled_letter.setter
|
||||
def is_precompiled_letter(self, value):
|
||||
pass
|
||||
|
||||
def _as_utils_template(self):
|
||||
if self.template_type == EMAIL_TYPE:
|
||||
return PlainTextEmailTemplate(self.__dict__)
|
||||
|
||||
@@ -389,7 +389,7 @@ class TemplateSchemaNested(TemplateSchema):
|
||||
is_precompiled_letter = fields.Method('get_is_precompiled_letter')
|
||||
|
||||
def get_is_precompiled_letter(self, template):
|
||||
return template.is_precompiled_letter
|
||||
return False
|
||||
|
||||
|
||||
class TemplateSchemaNoDetail(TemplateSchema):
|
||||
|
||||
@@ -706,7 +706,6 @@ def get_monthly_template_usage(service_id):
|
||||
'month': i.month,
|
||||
'year': i.year,
|
||||
'count': i.count,
|
||||
'is_precompiled_letter': i.is_precompiled_letter
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1057,7 +1056,7 @@ def get_returned_letters(service_id):
|
||||
'client_reference': x.client_reference if x.api_key_id else None,
|
||||
'reported_at': x.reported_at.strftime(DATE_FORMAT),
|
||||
'created_at': x.created_at.strftime(DATETIME_FORMAT_NO_TIMEZONE),
|
||||
# it doesn't make sense to show hidden/precompiled templates
|
||||
# it doesn't make sense to show hidden templates
|
||||
'template_name': x.template_name if not x.hidden else None,
|
||||
'template_id': x.template_id if not x.hidden else None,
|
||||
'template_version': x.template_version if not x.hidden else None,
|
||||
|
||||
@@ -37,7 +37,6 @@ def get_template_statistics_for_service_by_day(service_id):
|
||||
'template_id': str(row.template_id),
|
||||
'template_name': row.template_name,
|
||||
'template_type': row.notification_type,
|
||||
'is_precompiled_letter': row.is_precompiled_letter,
|
||||
'status': row.status
|
||||
}
|
||||
for row in data
|
||||
|
||||
@@ -86,14 +86,12 @@ def get_local_month_from_utc_column(column):
|
||||
|
||||
|
||||
def get_public_notify_type_text(notify_type, plural=False):
|
||||
from app.models import PRECOMPILED_LETTER, SMS_TYPE, UPLOAD_DOCUMENT
|
||||
from app.models import SMS_TYPE, UPLOAD_DOCUMENT
|
||||
notify_type_text = notify_type
|
||||
if notify_type == SMS_TYPE:
|
||||
notify_type_text = 'text message'
|
||||
elif notify_type == UPLOAD_DOCUMENT:
|
||||
notify_type_text = 'document'
|
||||
elif notify_type == PRECOMPILED_LETTER:
|
||||
notify_type_text = 'precompiled letter'
|
||||
|
||||
return '{}{}'.format(notify_type_text, 's' if plural else '')
|
||||
|
||||
|
||||
@@ -231,19 +231,6 @@ post_letter_request = {
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
post_precompiled_letter_request = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "POST precompiled letter notification schema",
|
||||
"type": "object",
|
||||
"title": "POST v2/notifications/letter",
|
||||
"properties": {
|
||||
"reference": {"type": "string"},
|
||||
"content": {"type": "string"},
|
||||
},
|
||||
"required": ["reference", "content"],
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
letter_content = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "Letter content for POST letter notification",
|
||||
|
||||
@@ -19,18 +19,11 @@ from app.config import QueueNames
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
KEY_TYPE_TEST,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_SENDING,
|
||||
PRIORITY,
|
||||
SMS_TYPE,
|
||||
Notification,
|
||||
)
|
||||
from app.notifications.process_letter_notifications import (
|
||||
create_letter_notification,
|
||||
)
|
||||
from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
send_notification_to_queue_detached,
|
||||
@@ -280,51 +273,6 @@ 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
|
||||
):
|
||||
if api_key.key_type == KEY_TYPE_TEAM:
|
||||
raise BadRequestError(message='Cannot send letters with a team api key', status_code=403)
|
||||
|
||||
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)
|
||||
|
||||
test_key = api_key.key_type == KEY_TYPE_TEST
|
||||
|
||||
status = NOTIFICATION_CREATED
|
||||
updated_at = None
|
||||
if test_key:
|
||||
# if we don't want to actually send the letter, then start it off in SENDING so we don't pick it up
|
||||
if current_app.config['NOTIFY_ENVIRONMENT'] in ['preview', 'development']:
|
||||
status = NOTIFICATION_SENDING
|
||||
# mark test letter as delivered and do not create a fake response later
|
||||
else:
|
||||
status = NOTIFICATION_DELIVERED
|
||||
updated_at = datetime.utcnow()
|
||||
|
||||
notification = create_letter_notification(letter_data=letter_data,
|
||||
service=service,
|
||||
template=template,
|
||||
api_key=api_key,
|
||||
status=status,
|
||||
reply_to_text=reply_to_text,
|
||||
updated_at=updated_at
|
||||
)
|
||||
|
||||
resp = create_response_for_post_notification(
|
||||
notification_id=notification.id,
|
||||
client_reference=notification.client_reference,
|
||||
template_id=notification.template_id,
|
||||
template_version=notification.template_version,
|
||||
notification_type=notification.notification_type,
|
||||
reply_to=reply_to_text,
|
||||
service_id=notification.service_id,
|
||||
template_with_content=template_with_content
|
||||
)
|
||||
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