mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
@@ -1,3 +1,4 @@
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import current_app
|
||||
@@ -10,6 +11,7 @@ from app.models import (
|
||||
JOB_STATUS_SCHEDULED, JOB_STATUS_PENDING,
|
||||
LETTER_TYPE
|
||||
)
|
||||
from app.variables import LETTER_TEST_API_FILENAME
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
@@ -108,6 +110,8 @@ def dao_get_future_scheduled_job_by_id_and_service_id(job_id, service_id):
|
||||
|
||||
|
||||
def dao_create_job(job):
|
||||
if not job.id:
|
||||
job.id = uuid.uuid4()
|
||||
job_stats = JobStatistics(
|
||||
job_id=job.id,
|
||||
updated_at=datetime.utcnow()
|
||||
@@ -139,9 +143,18 @@ def dao_get_jobs_older_than_limited_by(job_types, older_than=7, limit_days=2):
|
||||
|
||||
|
||||
def dao_get_all_letter_jobs():
|
||||
return db.session.query(Job).join(Job.template).filter(
|
||||
Template.template_type == LETTER_TYPE
|
||||
).order_by(desc(Job.created_at)).all()
|
||||
return db.session.query(
|
||||
Job
|
||||
).join(
|
||||
Job.template
|
||||
).filter(
|
||||
Template.template_type == LETTER_TYPE,
|
||||
# test letter jobs (or from research mode services) are created with a different filename,
|
||||
# exclude them so we don't see them on the send to CSV
|
||||
Job.original_file_name != LETTER_TEST_API_FILENAME
|
||||
).order_by(
|
||||
desc(Job.created_at)
|
||||
).all()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
|
||||
@@ -338,7 +338,8 @@ def get_notifications_for_service(
|
||||
filters.append(Notification.created_at < older_than_created_at)
|
||||
|
||||
if not include_jobs or (key_type and key_type != KEY_TYPE_NORMAL):
|
||||
filters.append(Notification.job_id.is_(None))
|
||||
# we can't say "job_id == None" here, because letters sent via the API still have a job_id :(
|
||||
filters.append(Notification.api_key_id != None) # noqa
|
||||
|
||||
if key_type is not None:
|
||||
filters.append(Notification.key_type == key_type)
|
||||
|
||||
@@ -207,14 +207,14 @@ def delete_service_and_all_associated_db_objects(service):
|
||||
_delete_commit(ProviderStatistics.query.filter_by(service=service))
|
||||
_delete_commit(InvitedUser.query.filter_by(service=service))
|
||||
_delete_commit(Permission.query.filter_by(service=service))
|
||||
_delete_commit(ApiKey.query.filter_by(service=service))
|
||||
_delete_commit(ApiKey.get_history_model().query.filter_by(service_id=service.id))
|
||||
_delete_commit(NotificationHistory.query.filter_by(service=service))
|
||||
_delete_commit(Notification.query.filter_by(service=service))
|
||||
_delete_commit(Job.query.filter_by(service=service))
|
||||
_delete_commit(Template.query.filter_by(service=service))
|
||||
_delete_commit(TemplateHistory.query.filter_by(service_id=service.id))
|
||||
_delete_commit(ServicePermission.query.filter_by(service_id=service.id))
|
||||
_delete_commit(ApiKey.query.filter_by(service=service))
|
||||
_delete_commit(ApiKey.get_history_model().query.filter_by(service_id=service.id))
|
||||
|
||||
verify_codes = VerifyCode.query.join(User).filter(User.id.in_([x.id for x in service.users]))
|
||||
list(map(db.session.delete, verify_codes))
|
||||
|
||||
Reference in New Issue
Block a user