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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user