notifications: do not unack automatically on .notify() (#13122)
It's also supported by the notification web-service.
This commit is contained in:
parent
8d9ac05b6d
commit
ad3a44d64c
|
@ -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)]}}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue