notifications: do not unack automatically on .notify() (#13122)

It's also supported by the notification web-service.
This commit is contained in:
Benjamin Dauvergne 2018-03-20 10:56:14 +01:00
parent 8d9ac05b6d
commit ad3a44d64c
3 changed files with 8 additions and 4 deletions

View File

@ -30,6 +30,7 @@ class NotificationSerializer(serializers.Serializer):
start_timestamp = serializers.DateTimeField(required=False, allow_null=True)
end_timestamp = serializers.DateTimeField(required=False, allow_null=True)
duration = serializers.IntegerField(required=False, allow_null=True, min_value=0)
acked = serializers.NullBooleanField(required=False)
class Add(GenericAPIView):
@ -52,7 +53,8 @@ class Add(GenericAPIView):
origin=data.get('origin'),
start_timestamp=data.get('start_timestamp'),
end_timestamp=data.get('end_timestamp'),
duration=data.get('duration')
duration=data.get('duration'),
acked=data.get('acked'),
)
except ValueError as e:
response = {'err': 1, 'err_desc': {'id': [unicode(e)]}}

View File

@ -91,7 +91,8 @@ class Notification(models.Model):
@classmethod
def notify(cls, user, summary, id=None, body='', url='', origin='',
start_timestamp=None, duration=None, end_timestamp=None):
start_timestamp=None, duration=None, end_timestamp=None,
acked=None):
'''
Create a new notification:
Notification.notify(user, 'summary') -> id
@ -116,8 +117,9 @@ class Notification(models.Model):
'origin': origin,
'start_timestamp': start_timestamp,
'end_timestamp': end_timestamp,
'acked': False,
}
if acked is not None:
defaults['acked'] = acked
try:
pk = int(id)

View File

@ -55,7 +55,7 @@ def test_notification_api(user, user2):
Notification.objects.visible(user).ack()
assert Notification.objects.get().acked is True
Notification.notify(user, 'notirefoo', id=str(notification.pk))
Notification.notify(user, 'notirefoo', id=str(notification.pk), acked=False)
assert Notification.objects.count() == 1
assert Notification.objects.get().summary == 'notirefoo'
# we updated the notification, it's un-acked