mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-04 13:41:38 -04:00
Merge pull request #3263 from alphagov/fix-new-jobs-showing-as-deleted
Use time to determine why notifications don’t exist
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from flask import (
|
||||
current_app,
|
||||
@@ -29,8 +28,7 @@ def new_password(token):
|
||||
|
||||
email_address = json.loads(token_data)['email']
|
||||
user = User.from_email_address(email_address)
|
||||
if user.password_changed_at and datetime.strptime(user.password_changed_at, '%Y-%m-%d %H:%M:%S.%f') > \
|
||||
datetime.strptime(json.loads(token_data)['created_at'], '%Y-%m-%d %H:%M:%S.%f'):
|
||||
if user.password_changed_more_recently_than(json.loads(token_data)['created_at']):
|
||||
flash('The link in the email has already been used')
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ from flask import (
|
||||
)
|
||||
from flask_login import current_user
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
|
||||
|
||||
from app import (
|
||||
billing_api_client,
|
||||
@@ -475,8 +476,10 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id):
|
||||
email_address=notification["to"],
|
||||
is_default=is_default
|
||||
)
|
||||
created_at_no_tz = notification["created_at"][:-6]
|
||||
seconds_since_sending = (datetime.utcnow() - datetime.strptime(created_at_no_tz, '%Y-%m-%dT%H:%M:%S.%f')).seconds
|
||||
seconds_since_sending = (
|
||||
utc_string_to_aware_gmt_datetime(datetime.utcnow().isoformat()) -
|
||||
utc_string_to_aware_gmt_datetime(notification['created_at'])
|
||||
).seconds
|
||||
if notification["status"] in FAILURE_STATUSES or (
|
||||
notification["status"] in SENDING_STATUSES and
|
||||
seconds_since_sending > current_app.config['REPLY_TO_EMAIL_ADDRESS_VALIDATION_TIMEOUT']
|
||||
|
||||
@@ -5,6 +5,10 @@ from notifications_utils.letter_timings import (
|
||||
get_letter_timings,
|
||||
letter_can_be_cancelled,
|
||||
)
|
||||
from notifications_utils.timezones import (
|
||||
local_timezone,
|
||||
utc_string_to_aware_gmt_datetime,
|
||||
)
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.models import JSONModel, ModelList
|
||||
@@ -23,6 +27,7 @@ class Job(JSONModel):
|
||||
'template_version',
|
||||
'original_file_name',
|
||||
'created_at',
|
||||
'processing_started',
|
||||
'notification_count',
|
||||
'created_by',
|
||||
}
|
||||
@@ -47,6 +52,12 @@ class Job(JSONModel):
|
||||
def scheduled_for(self):
|
||||
return self._dict.get('scheduled_for')
|
||||
|
||||
@property
|
||||
def processing_started(self):
|
||||
if not self._dict.get('processing_started'):
|
||||
return None
|
||||
return utc_string_to_aware_gmt_datetime(self._dict['processing_started'])
|
||||
|
||||
def _aggregate_statistics(self, *statuses):
|
||||
return sum(
|
||||
outcome['count'] for outcome in self._dict['statistics']
|
||||
@@ -94,6 +105,17 @@ class Job(JSONModel):
|
||||
def finished_processing(self):
|
||||
return self.notification_count == self.notifications_sent
|
||||
|
||||
@property
|
||||
def awaiting_processing_or_recently_processed(self):
|
||||
if not self.processing_started:
|
||||
# Assume that if processing hasn’t started yet then the job
|
||||
# must have been created recently enough to not have any
|
||||
# notifications yet
|
||||
return True
|
||||
return (
|
||||
datetime.utcnow().astimezone(local_timezone) - self.processing_started
|
||||
).days < 1
|
||||
|
||||
@property
|
||||
def template_id(self):
|
||||
return self._dict['template']
|
||||
@@ -124,7 +146,8 @@ class Job(JSONModel):
|
||||
return False
|
||||
|
||||
if not letter_can_be_cancelled(
|
||||
'created', datetime.strptime(self.created_at[:-6], '%Y-%m-%dT%H:%M:%S.%f')
|
||||
'created',
|
||||
utc_string_to_aware_gmt_datetime(self.created_at).replace(tzinfo=None)
|
||||
):
|
||||
return False
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from flask import abort, current_app, request, session
|
||||
from flask_login import AnonymousUserMixin, UserMixin, login_user
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.models import JSONModel, ModelList
|
||||
@@ -108,6 +109,15 @@ class User(JSONModel, UserMixin):
|
||||
response = user_api_client.update_password(self.id, password)
|
||||
self.__init__(response)
|
||||
|
||||
def password_changed_more_recently_than(self, datetime_string):
|
||||
if not self.password_changed_at:
|
||||
return False
|
||||
return utc_string_to_aware_gmt_datetime(
|
||||
self.password_changed_at
|
||||
) > utc_string_to_aware_gmt_datetime(
|
||||
datetime_string
|
||||
)
|
||||
|
||||
def set_permissions(self, service_id, permissions, folder_permissions):
|
||||
user_api_client.set_user_permissions(
|
||||
self.id,
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
notifications,
|
||||
caption=uploaded_file_name,
|
||||
caption_visible=False,
|
||||
empty_message='These messages have been deleted because they were sent more than {} days ago'.format(service_data_retention_days) if job.status == 'finished' else 'No messages to show yet…',
|
||||
empty_message='No messages to show yet…' if job.awaiting_processing_or_recently_processed else 'These messages have been deleted because they were sent more than {} days ago'.format(service_data_retention_days),
|
||||
field_headings=[
|
||||
'Recipient',
|
||||
'Status'
|
||||
|
||||
Reference in New Issue
Block a user