mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 18:23:01 -04:00
Merge pull request #1534 from GSA/invite-expiration-fix
Invite expiration fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from datetime import timedelta
|
import os
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
@@ -95,6 +96,32 @@ def dao_create_notification(notification):
|
|||||||
# notify-api-1454 insert only if it doesn't exist
|
# notify-api-1454 insert only if it doesn't exist
|
||||||
if not dao_notification_exists(notification.id):
|
if not dao_notification_exists(notification.id):
|
||||||
db.session.add(notification)
|
db.session.add(notification)
|
||||||
|
# There have been issues with invites expiring.
|
||||||
|
# Ensure the created at value is set and debug.
|
||||||
|
if notification.notification_type == "email":
|
||||||
|
orig_time = notification.created_at
|
||||||
|
now_time = utc_now()
|
||||||
|
try:
|
||||||
|
diff_time = now_time - orig_time
|
||||||
|
except TypeError:
|
||||||
|
try:
|
||||||
|
orig_time = datetime.strptime(orig_time, "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
|
except ValueError:
|
||||||
|
orig_time = datetime.strptime(orig_time, "%Y-%m-%d")
|
||||||
|
diff_time = now_time - orig_time
|
||||||
|
current_app.logger.error(
|
||||||
|
f"dao_create_notification orig created at: {orig_time} and now created at: {now_time}"
|
||||||
|
)
|
||||||
|
if diff_time.total_seconds() > 300:
|
||||||
|
current_app.logger.error(
|
||||||
|
"Something is wrong with notification.created_at in email!"
|
||||||
|
)
|
||||||
|
if os.getenv("NOTIFY_ENVIRONMENT") not in ["test"]:
|
||||||
|
notification.created_at = now_time
|
||||||
|
dao_update_notification(notification)
|
||||||
|
current_app.logger.error(
|
||||||
|
f"Email notification created_at reset to {notification.created_at}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def country_records_delivery(phone_prefix):
|
def country_records_delivery(phone_prefix):
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ def _create_service_invite(invited_user, nonce, state):
|
|||||||
"service_name": invited_user.service.name,
|
"service_name": invited_user.service.name,
|
||||||
"url": url,
|
"url": url,
|
||||||
}
|
}
|
||||||
|
created_at = utc_now()
|
||||||
saved_notification = persist_notification(
|
saved_notification = persist_notification(
|
||||||
template_id=template.id,
|
template_id=template.id,
|
||||||
template_version=template.version,
|
template_version=template.version,
|
||||||
@@ -78,6 +78,7 @@ def _create_service_invite(invited_user, nonce, state):
|
|||||||
api_key_id=None,
|
api_key_id=None,
|
||||||
key_type=KeyType.NORMAL,
|
key_type=KeyType.NORMAL,
|
||||||
reply_to_text=invited_user.from_user.email_address,
|
reply_to_text=invited_user.from_user.email_address,
|
||||||
|
created_at=created_at,
|
||||||
)
|
)
|
||||||
saved_notification.personalisation = personalisation
|
saved_notification.personalisation = personalisation
|
||||||
redis_store.set(
|
redis_store.set(
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ def test_create_nightly_notification_status_triggers_relevant_tasks(
|
|||||||
mock_celery = mocker.patch(
|
mock_celery = mocker.patch(
|
||||||
"app.celery.reporting_tasks.create_nightly_notification_status_for_service_and_day"
|
"app.celery.reporting_tasks.create_nightly_notification_status_for_service_and_day"
|
||||||
).apply_async
|
).apply_async
|
||||||
|
|
||||||
for notification_type in NotificationType:
|
for notification_type in NotificationType:
|
||||||
template = create_template(sample_service, template_type=notification_type)
|
template = create_template(sample_service, template_type=notification_type)
|
||||||
create_notification(template=template, created_at=notification_date)
|
create_notification(template=template, created_at=notification_date)
|
||||||
|
|||||||
Reference in New Issue
Block a user