diff --git a/lemur/certificates/models.py b/lemur/certificates/models.py index 734d2a0e..ff44f804 100644 --- a/lemur/certificates/models.py +++ b/lemur/certificates/models.py @@ -115,7 +115,7 @@ class Certificate(db.Model): self.notifications = kwargs.get('notifications', []) self.description = kwargs.get('description') self.roles = list(set(kwargs.get('roles', []))) - self.replaces = kwargs.get('replacements', []) + self.replaces = kwargs.get('replaces', []) self.rotation = kwargs.get('rotation') self.signing_algorithm = defaults.signing_algorithm(cert) self.bits = defaults.bitstrength(cert) diff --git a/lemur/certificates/schemas.py b/lemur/certificates/schemas.py index ccc8fd2e..6cc4fa70 100644 --- a/lemur/certificates/schemas.py +++ b/lemur/certificates/schemas.py @@ -54,7 +54,8 @@ class CertificateInputSchema(CertificateCreationSchema): destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True) notifications = fields.Nested(AssociatedNotificationSchema, missing=[], many=True) - replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) + replaces = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) + replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) # deprecated roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True) csr = fields.String(validate=validators.csr) @@ -76,18 +77,28 @@ class CertificateInputSchema(CertificateCreationSchema): validators.dates(data) @pre_load - def ensure_dates(self, data): + def load_data(self, data): + if data.get('replacements'): + data['replaces'] = data['replacements'] # TODO remove when field is deprecated return missing.convert_validity_years(data) class CertificateEditInputSchema(CertificateSchema): notify = fields.Boolean() owner = fields.String() + destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True) notifications = fields.Nested(AssociatedNotificationSchema, missing=[], many=True) - replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) + replaces = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) + replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) # deprecated roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True) + @pre_load + def load_data(self, data): + if data.get('replacements'): + data['replaces'] = data['replacements'] # TODO remove when field is deprecated + return data + @post_load def enforce_notifications(self, data): """ @@ -113,13 +124,13 @@ class CertificateNestedOutputSchema(LemurOutputSchema): name = fields.String() # Note aliasing is the first step in deprecating these fields. - cn = fields.String() + cn = fields.String() # deprecated common_name = fields.String(attribute='cn') - not_after = fields.DateTime() + not_after = fields.DateTime() # deprecated validity_end = ArrowDateTime(attribute='not_after') - not_before = fields.DateTime() + not_before = fields.DateTime() # deprecated validity_start = ArrowDateTime(attribute='not_before') owner = fields.Email() @@ -175,7 +186,7 @@ class CertificateOutputSchema(LemurOutputSchema): authority = fields.Nested(AuthorityNestedOutputSchema) roles = fields.Nested(RoleNestedOutputSchema, many=True) endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[]) - replaced = fields.Nested(CertificateNestedOutputSchema, many=True) + replaced_by = fields.Nested(CertificateNestedOutputSchema, many=True, attribute='replaced') class CertificateUploadInputSchema(CertificateCreationSchema): @@ -188,7 +199,7 @@ class CertificateUploadInputSchema(CertificateCreationSchema): destinations = fields.Nested(AssociatedDestinationSchema, missing=[], many=True) notifications = fields.Nested(AssociatedNotificationSchema, missing=[], many=True) - replacements = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) + replaces = fields.Nested(AssociatedCertificateSchema, missing=[], many=True) roles = fields.Nested(AssociatedRoleSchema, missing=[], many=True) @validates_schema @@ -209,7 +220,7 @@ class CertificateNotificationOutputSchema(LemurOutputSchema): owner = fields.Email() user = fields.Nested(UserNestedOutputSchema) validity_end = ArrowDateTime(attribute='not_after') - replaced = fields.Nested(CertificateNestedOutputSchema, many=True) + replaced_by = fields.Nested(CertificateNestedOutputSchema, many=True, attribute='replaced') endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[]) diff --git a/lemur/plugins/lemur_email/templates/rotation.html b/lemur/plugins/lemur_email/templates/rotation.html index 52abc84a..521eb327 100644 --- a/lemur/plugins/lemur_email/templates/rotation.html +++ b/lemur/plugins/lemur_email/templates/rotation.html @@ -110,12 +110,12 @@ - {{ certificate.replaced.name }} + {{ certificate.replacedBy[0].name }}
-
{{ certificate.replaced[0].owner }} -
{{ certificate.replaced[0].validityEnd | time }} - Details +
{{ certificate.replacedBy[0].owner }} +
{{ certificate.replacedBy[0].validityEnd | time }} + Details
diff --git a/lemur/static/app/angular/certificates/certificate/certificate.js b/lemur/static/app/angular/certificates/certificate/certificate.js index eb29c6fc..e786619a 100644 --- a/lemur/static/app/angular/certificates/certificate/certificate.js +++ b/lemur/static/app/angular/certificates/certificate/certificate.js @@ -328,7 +328,6 @@ angular.module('lemur') } ]; - PluginService.getByType('destination').then(function (plugins) { $scope.plugins = plugins; }); diff --git a/lemur/static/app/angular/certificates/certificate/replaces.tpl.html b/lemur/static/app/angular/certificates/certificate/replaces.tpl.html index 0df938d4..b7e7a91c 100644 --- a/lemur/static/app/angular/certificates/certificate/replaces.tpl.html +++ b/lemur/static/app/angular/certificates/certificate/replaces.tpl.html @@ -4,23 +4,23 @@
- -
- - - + + +
{{ replacement.name }}{{ replacement.description }}
{{ replaces.name }}{{ replaces.description }} - +
diff --git a/lemur/static/app/angular/certificates/services.js b/lemur/static/app/angular/certificates/services.js index 0495741c..16ab6935 100644 --- a/lemur/static/app/angular/certificates/services.js +++ b/lemur/static/app/angular/certificates/services.js @@ -81,15 +81,15 @@ angular.module('lemur') removeDestination: function (index) { this.destinations.splice(index, 1); }, - attachReplacement: function (replacement) { - this.selectedReplacement = null; - if (this.replacements === undefined) { - this.replacements = []; + attachReplaces: function (replaces) { + this.selectedReplaces = null; + if (this.replaces === undefined) { + this.replaces = []; } - this.replacements.push(replacement); + this.replaces.push(replaces); }, - removeReplacement: function (index) { - this.replacements.splice(index, 1); + removeReplaces: function (index) { + this.replaces.splice(index, 1); }, attachNotification: function (notification) { this.selectedNotification = null; @@ -169,9 +169,9 @@ angular.module('lemur') }); }; - CertificateService.getReplacements = function (certificate) { - return certificate.getList('replacements').then(function (replacements) { - certificate.replacements = replacements; + CertificateService.getReplaces = function (certificate) { + return certificate.getList('replaces').then(function (replaces) { + certificate.replaces = replaces; }); }; diff --git a/lemur/static/app/angular/certificates/view/view.tpl.html b/lemur/static/app/angular/certificates/view/view.tpl.html index 7387741e..40cd5fe6 100644 --- a/lemur/static/app/angular/certificates/view/view.tpl.html +++ b/lemur/static/app/angular/certificates/view/view.tpl.html @@ -170,9 +170,9 @@ Replaces diff --git a/lemur/tests/test_certificates.py b/lemur/tests/test_certificates.py index c8fd1d1d..278ffbc8 100644 --- a/lemur/tests/test_certificates.py +++ b/lemur/tests/test_certificates.py @@ -153,7 +153,7 @@ def test_certificate_input_schema(client, authority): assert data['country'] == 'US' assert data['location'] == 'Los Gatos' - assert len(data.keys()) == 16 + assert len(data.keys()) == 17 def test_certificate_input_with_extensions(client, authority):