diff --git a/docs/release-notes/version-2.8.md b/docs/release-notes/version-2.8.md index 5ca86217a..fb177252f 100644 --- a/docs/release-notes/version-2.8.md +++ b/docs/release-notes/version-2.8.md @@ -1,5 +1,13 @@ # NetBox v2.8 +## v2.8.6 (FUTURE) + +### Bug Fixes + +* [#4702](https://github.com/netbox-community/netbox/issues/4702) - Catch IntegrityError exception when adding a non-unique secret + +--- + ## v2.8.5 (2020-05-26) **Note:** The minimum required version of PostgreSQL is now 9.6. diff --git a/netbox/secrets/forms.py b/netbox/secrets/forms.py index 089771bd8..296469900 100644 --- a/netbox/secrets/forms.py +++ b/netbox/secrets/forms.py @@ -115,6 +115,16 @@ class SecretForm(BootstrapMixin, CustomFieldModelForm): 'plaintext2': "The two given plaintext values do not match. Please check your input." }) + # Validate uniqueness + if Secret.objects.filter( + device=self.cleaned_data['device'], + role=self.cleaned_data['role'], + name=self.cleaned_data['name'] + ).exists(): + raise forms.ValidationError( + "Each secret assigned to a device must have a unique combination of role and name" + ) + class SecretCSVForm(CustomFieldModelCSVForm): device = CSVModelChoiceField(