Don't update sent notifications (dao)

This commit is contained in:
Imdad Ahad
2017-04-27 16:55:39 +01:00
parent 349fb3529e
commit c5bd685cef
2 changed files with 31 additions and 8 deletions

View File

@@ -175,11 +175,14 @@ def _update_notification_status(notification, status):
def update_notification_status_by_id(notification_id, status):
notification = Notification.query.with_lockmode("update").filter(
Notification.id == notification_id,
or_(Notification.status == NOTIFICATION_CREATED,
or_(
Notification.status == NOTIFICATION_CREATED,
Notification.status == NOTIFICATION_SENDING,
Notification.status == NOTIFICATION_PENDING)).first()
Notification.status == NOTIFICATION_PENDING,
Notification.status == NOTIFICATION_SENT
)).first()
if not notification:
if not notification or notification.status == NOTIFICATION_SENT:
return None
return _update_notification_status(
@@ -193,10 +196,13 @@ def update_notification_status_by_id(notification_id, status):
def update_notification_status_by_reference(reference, status):
notification = Notification.query.filter(
Notification.reference == reference,
or_(Notification.status == NOTIFICATION_SENDING,
Notification.status == NOTIFICATION_PENDING)).first()
or_(
Notification.status == NOTIFICATION_SENDING,
Notification.status == NOTIFICATION_PENDING,
Notification.status == NOTIFICATION_SENT
)).first()
if not notification:
if not notification or notification.status == NOTIFICATION_SENT:
return None
return _update_notification_status(