notifications: don't make ack() imply forget() (#25186)

This commit is contained in:
Frédéric Péters 2018-07-10 14:46:10 +02:00
parent 1c51ae901b
commit e985190952
2 changed files with 6 additions and 16 deletions

View File

@ -42,8 +42,7 @@ class NotificationQuerySet(QuerySet):
return qs.filter(search_id)
def ack(self):
self.filter(end_timestamp__isnull=True).update(acked=True, end_timestamp=now() - timedelta(seconds=5))
self.filter(end_timestamp__isnull=False).update(acked=True)
self.update(acked=True)
def visible(self, user=None, n=None):
qs = self
@ -149,23 +148,14 @@ class Notification(models.Model):
notification = Notification.objects.create(user=user, **defaults)
return notification
@property
def visible(self):
return self.end_timestamp > now()
def forget(self):
self.end_timestamp = now() - timedelta(seconds=5)
self.acked = True
self.save(update_fields=['end_timestamp', 'acked'])
def ack(self):
if self.end_timestamp:
self.acked = True
self.save(update_fields=['acked'])
else:
self.acked = True
self.end_timestamp = now() - timedelta(seconds=5)
self.save(update_fields=['acked', 'end_timestamp'])
self.acked = True
self.save(update_fields=['acked'])
@register_cell_class

View File

@ -458,9 +458,9 @@ def test_notification_never_expire(app, freezer, rf, john_doe):
Notification.objects.visible(john_doe).ack()
# acking a notification without and end_timestamp, forget it
# acking a notification without and end_timestamp, still visible
freezer.move_to(start + timedelta(days=365, seconds=1))
content = cell.render(context)
assert Notification.objects.visible(john_doe).count() == 0
assert 'notibar' not in content
assert Notification.objects.visible(john_doe).count() == 1
assert 'notibar' in content
assert 'notifoo' not in content