mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Ignore services that have letters_as_pdf permission
- We don't want to process the letters as a build file for api calls when the service is generating letters as pdf.
This commit is contained in:
@@ -26,6 +26,8 @@ from app.models import (
|
|||||||
Notification,
|
Notification,
|
||||||
NotificationHistory,
|
NotificationHistory,
|
||||||
ScheduledNotification,
|
ScheduledNotification,
|
||||||
|
Service,
|
||||||
|
ServicePermission,
|
||||||
Template,
|
Template,
|
||||||
TemplateHistory,
|
TemplateHistory,
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
@@ -541,14 +543,28 @@ def dao_set_created_live_letter_api_notifications_to_pending():
|
|||||||
this is used in the run_scheduled_jobs task, so we put a FOR UPDATE lock on the job table for the duration of
|
this is used in the run_scheduled_jobs task, so we put a FOR UPDATE lock on the job table for the duration of
|
||||||
the transaction so that if the task is run more than once concurrently, one task will block the other select
|
the transaction so that if the task is run more than once concurrently, one task will block the other select
|
||||||
from completing until it commits.
|
from completing until it commits.
|
||||||
|
|
||||||
|
Note - do not process services that have letters_as_pdf permission as they
|
||||||
|
will get processed when the letters PDF zip task is created
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Ignore services that have letters_as_pdf permission
|
||||||
|
services_without_letters_as_pdf = [
|
||||||
|
s.id for s in Service.query.filter(
|
||||||
|
~Service.permissions.any(
|
||||||
|
ServicePermission.permission == 'letters_as_pdf'
|
||||||
|
)
|
||||||
|
).all()
|
||||||
|
]
|
||||||
|
|
||||||
notifications = db.session.query(
|
notifications = db.session.query(
|
||||||
Notification
|
Notification
|
||||||
).filter(
|
).filter(
|
||||||
Notification.notification_type == LETTER_TYPE,
|
Notification.notification_type == LETTER_TYPE,
|
||||||
Notification.status == NOTIFICATION_CREATED,
|
Notification.status == NOTIFICATION_CREATED,
|
||||||
Notification.key_type == KEY_TYPE_NORMAL,
|
Notification.key_type == KEY_TYPE_NORMAL,
|
||||||
Notification.api_key != None # noqa
|
Notification.api_key != None, # noqa
|
||||||
|
Notification.service_id.in_(services_without_letters_as_pdf)
|
||||||
).with_for_update(
|
).with_for_update(
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
from app.models import (
|
from app.models import (
|
||||||
|
Notification,
|
||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
NOTIFICATION_PENDING,
|
NOTIFICATION_PENDING,
|
||||||
NOTIFICATION_SENDING,
|
NOTIFICATION_SENDING,
|
||||||
KEY_TYPE_TEST,
|
KEY_TYPE_TEST,
|
||||||
KEY_TYPE_NORMAL
|
KEY_TYPE_NORMAL,
|
||||||
|
LETTER_TYPE
|
||||||
)
|
)
|
||||||
from app.dao.notifications_dao import dao_set_created_live_letter_api_notifications_to_pending
|
from app.dao.notifications_dao import dao_set_created_live_letter_api_notifications_to_pending
|
||||||
|
|
||||||
from tests.app.db import create_notification
|
from tests.app.db import create_notification, create_service, create_template
|
||||||
|
|
||||||
|
|
||||||
def test_should_only_get_letter_notifications(
|
def test_should_only_get_letter_notifications(
|
||||||
@@ -23,6 +25,22 @@ def test_should_only_get_letter_notifications(
|
|||||||
assert ret == [sample_letter_notification]
|
assert ret == [sample_letter_notification]
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_ignore_letters_as_pdf(
|
||||||
|
sample_letter_notification,
|
||||||
|
):
|
||||||
|
service = create_service(service_permissions=[LETTER_TYPE, 'letters_as_pdf'])
|
||||||
|
template = create_template(service, template_type=LETTER_TYPE)
|
||||||
|
create_notification(template)
|
||||||
|
|
||||||
|
all_noti = Notification.query.all()
|
||||||
|
assert len(all_noti) == 2
|
||||||
|
|
||||||
|
ret = dao_set_created_live_letter_api_notifications_to_pending()
|
||||||
|
|
||||||
|
assert sample_letter_notification.status == NOTIFICATION_PENDING
|
||||||
|
assert ret == [sample_letter_notification]
|
||||||
|
|
||||||
|
|
||||||
def test_should_only_get_created_letters(sample_letter_template):
|
def test_should_only_get_created_letters(sample_letter_template):
|
||||||
created_noti = create_notification(sample_letter_template, status=NOTIFICATION_CREATED)
|
created_noti = create_notification(sample_letter_template, status=NOTIFICATION_CREATED)
|
||||||
create_notification(sample_letter_template, status=NOTIFICATION_PENDING)
|
create_notification(sample_letter_template, status=NOTIFICATION_PENDING)
|
||||||
|
|||||||
Reference in New Issue
Block a user