Merge pull request #3428 from jtschladen/add-remove-certs-for-notification
Add/remove certs for notification UI
This commit is contained in:
commit
de06f13bb1
@ -200,6 +200,7 @@ def send_plugin_notification(event_type, data, recipients, notification):
|
||||
"notification_type": event_type,
|
||||
"notification_plugin": notification.plugin.slug,
|
||||
"certificate_targets": recipients,
|
||||
"plugin": notification.plugin.slug,
|
||||
}
|
||||
status = FAILURE_METRIC_STATUS
|
||||
try:
|
||||
|
@ -21,6 +21,8 @@ class NotificationInputSchema(LemurInputSchema):
|
||||
active = fields.Boolean()
|
||||
plugin = fields.Nested(PluginInputSchema, required=True)
|
||||
certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[])
|
||||
added_certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[])
|
||||
removed_certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[])
|
||||
|
||||
|
||||
class NotificationOutputSchema(LemurOutputSchema):
|
||||
|
@ -104,7 +104,7 @@ def create(label, plugin_name, options, description, certificates):
|
||||
return database.create(notification)
|
||||
|
||||
|
||||
def update(notification_id, label, plugin_name, options, description, active, certificates):
|
||||
def update(notification_id, label, plugin_name, options, description, active, added_certificates, removed_certificates):
|
||||
"""
|
||||
Updates an existing notification.
|
||||
|
||||
@ -114,7 +114,8 @@ def update(notification_id, label, plugin_name, options, description, active, ce
|
||||
:param options:
|
||||
:param description:
|
||||
:param active:
|
||||
:param certificates:
|
||||
:param added_certificates:
|
||||
:param removed_certificates:
|
||||
:rtype: Notification
|
||||
:return:
|
||||
"""
|
||||
@ -125,7 +126,8 @@ def update(notification_id, label, plugin_name, options, description, active, ce
|
||||
notification.options = options
|
||||
notification.description = description
|
||||
notification.active = active
|
||||
notification.certificates = certificates
|
||||
notification.certificates = notification.certificates + added_certificates
|
||||
notification.certificates = [c for c in notification.certificates if c not in removed_certificates]
|
||||
|
||||
return database.update(notification)
|
||||
|
||||
|
@ -117,7 +117,7 @@ class NotificationsList(AuthenticatedResource):
|
||||
"""
|
||||
.. http:post:: /notifications
|
||||
|
||||
Creates a new account
|
||||
Creates a new notification
|
||||
|
||||
**Example request**:
|
||||
|
||||
@ -214,9 +214,12 @@ class NotificationsList(AuthenticatedResource):
|
||||
"id": 2
|
||||
}
|
||||
|
||||
:arg accountNumber: aws account number
|
||||
:arg label: human readable account label
|
||||
:arg comments: some description about the account
|
||||
:label label: notification name
|
||||
:label slug: notification plugin slug
|
||||
:label plugin_options: notification plugin options
|
||||
:label description: notification description
|
||||
:label active: whether or not the notification is active/enabled
|
||||
:label certificates: certificates to attach to notification
|
||||
:reqheader Authorization: OAuth token to authenticate
|
||||
:statuscode 200: no error
|
||||
"""
|
||||
@ -239,7 +242,7 @@ class Notifications(AuthenticatedResource):
|
||||
"""
|
||||
.. http:get:: /notifications/1
|
||||
|
||||
Get a specific account
|
||||
Get a specific notification
|
||||
|
||||
**Example request**:
|
||||
|
||||
@ -306,17 +309,29 @@ class Notifications(AuthenticatedResource):
|
||||
"""
|
||||
.. http:put:: /notifications/1
|
||||
|
||||
Updates an account
|
||||
Updates a notification
|
||||
|
||||
**Example request**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
POST /notifications/1 HTTP/1.1
|
||||
PUT /notifications/1 HTTP/1.1
|
||||
Host: example.com
|
||||
Accept: application/json, text/javascript
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
|
||||
{
|
||||
"label": "labelChanged",
|
||||
"plugin": {
|
||||
"slug": "email-notification",
|
||||
"plugin_options": "???"
|
||||
},
|
||||
"description": "Sample notification",
|
||||
"active": "true",
|
||||
"added_certificates": "???",
|
||||
"removed_certificates": "???"
|
||||
}
|
||||
|
||||
|
||||
**Example response**:
|
||||
|
||||
@ -328,14 +343,24 @@ class Notifications(AuthenticatedResource):
|
||||
|
||||
{
|
||||
"id": 1,
|
||||
"accountNumber": 11111111111,
|
||||
"label": "labelChanged",
|
||||
"comments": "this is a thing"
|
||||
"plugin": {
|
||||
"slug": "email-notification",
|
||||
"plugin_options": "???"
|
||||
},
|
||||
"description": "Sample notification",
|
||||
"active": "true",
|
||||
"added_certificates": "???",
|
||||
"removed_certificates": "???"
|
||||
}
|
||||
|
||||
:arg accountNumber: aws account number
|
||||
:arg label: human readable account label
|
||||
:arg comments: some description about the account
|
||||
:label label: notification name
|
||||
:label slug: notification plugin slug
|
||||
:label plugin_options: notification plugin options
|
||||
:label description: notification description
|
||||
:label active: whether or not the notification is active/enabled
|
||||
:label added_certificates: certificates to add
|
||||
:label removed_certificates: certificates to remove
|
||||
:reqheader Authorization: OAuth token to authenticate
|
||||
:statuscode 200: no error
|
||||
"""
|
||||
@ -346,7 +371,8 @@ class Notifications(AuthenticatedResource):
|
||||
data["plugin"]["plugin_options"],
|
||||
data["description"],
|
||||
data["active"],
|
||||
data["certificates"],
|
||||
data["added_certificates"],
|
||||
data["removed_certificates"],
|
||||
)
|
||||
|
||||
def delete(self, notification_id):
|
||||
|
@ -8,10 +8,35 @@ angular.module('lemur')
|
||||
if (this.certificates === undefined) {
|
||||
this.certificates = [];
|
||||
}
|
||||
if (this.addedCertificates === undefined) {
|
||||
this.addedCertificates = [];
|
||||
}
|
||||
if (_.some(this.addedCertificates, function (cert) {
|
||||
return cert.id === certificate.id;
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
this.certificates.push(certificate);
|
||||
this.addedCertificates.push(certificate);
|
||||
if (this.removedCertificates !== undefined) {
|
||||
const indexInRemovedList = _.findIndex(this.removedCertificates, function (cert) {
|
||||
return cert.id === certificate.id;
|
||||
});
|
||||
this.removedCertificates.splice(indexInRemovedList, 1);
|
||||
}
|
||||
},
|
||||
removeCertificate: function (index) {
|
||||
this.certificates.splice(index, 1);
|
||||
if (this.removedCertificates === undefined) {
|
||||
this.removedCertificates = [];
|
||||
}
|
||||
const removedCert = this.certificates.splice(index, 1)[0];
|
||||
this.removedCertificates.push(removedCert);
|
||||
if (this.addedCertificates !== undefined) {
|
||||
const indexInAddedList = _.findIndex(this.addedCertificates, function (cert) {
|
||||
return cert.id === removedCert.id;
|
||||
});
|
||||
this.addedCertificates.splice(indexInAddedList, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user