Fix issue with repeatedly adding and removing

This commit is contained in:
Jasmine Schladen 2021-02-19 18:25:05 -08:00
parent fbba3034fc
commit b3d0b7ce1b
3 changed files with 19 additions and 11 deletions

View File

@ -20,6 +20,7 @@ class NotificationInputSchema(LemurInputSchema):
description = fields.String()
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=[])

View File

@ -242,7 +242,7 @@ class Notifications(AuthenticatedResource):
"""
.. http:get:: /notifications/1
Get a specific account
Get a specific notification
**Example request**:

View File

@ -11,26 +11,31 @@ angular.module('lemur')
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 removedIndex = this.removedCertificates.indexOf(certificate);
if (removedIndex > -1) {
this.removedCertificates.splice(removedIndex, 1);
}
const indexInRemovedList = _.findIndex(this.removedCertificates, function (cert) {
return cert.id === certificate.id;
});
this.removedCertificates.splice(indexInRemovedList, 1);
}
},
removeCertificate: function (index) {
if (this.removedCertificates === undefined) {
this.removedCertificates = [];
}
const removedCert = this.certificates.splice(index, 1);
const removedCert = this.certificates.splice(index, 1)[0];
this.removedCertificates.push(removedCert);
if (this.addedCertificates !== undefined) {
const addedIndex = this.addedCertificates.indexOf(removedCert);
if (addedIndex > -1) {
this.addedCertificates.splice(addedIndex, 1);
}
const indexInAddedList = _.findIndex(this.addedCertificates, function (cert) {
return cert.id === removedCert.id;
});
this.addedCertificates.splice(indexInAddedList, 1);
}
}
});
@ -72,7 +77,9 @@ angular.module('lemur')
};
NotificationService.update = function (notification) {
this.certificates = [];
// this.certificates = [];
// this.removedCertificates = [];
// this.addedCertificates = [];
return notification.put();
};