From 8977c5ddbfba801a6cbd5ad73d5ba5634e1a7449 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Sat, 29 Aug 2015 12:02:50 -0700 Subject: [PATCH] Ensuring notifications follow owner --- lemur/certificates/service.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lemur/certificates/service.py b/lemur/certificates/service.py index 8a1e20fa..6fb2f634 100644 --- a/lemur/certificates/service.py +++ b/lemur/certificates/service.py @@ -85,11 +85,22 @@ def update(cert_id, owner, description, active, destinations, notifications): :param active: :return: """ + from lemur.notifications import service as notification_service cert = get(cert_id) - cert.owner = owner cert.active = active cert.description = description + # we might have to create new notifications if the owner changes + if owner != cert.owner: + for n in cert.notifications: + notification_name = "DEFAULT_{0}".format(cert.owner.split('@')[0].upper()) + if n.name == notification_name: + cert.notifications.remove(n) + + cert.owner = owner + notification_name = "DEFAULT_{0}".format(cert.owner.split('@')[0].upper()) + notifications = notification_service.create_default_expiration_notifications(notification_name, owner) + database.update_list(cert, 'notifications', Notification, notifications) database.update_list(cert, 'destinations', Destination, destinations)